Add light button with for loop and enum

i want to add a specific light button with this script not call a menu from where i can choose what light i want to add.

enum = [
    ("object.light_add")
]

for index, e in enumerate(enum):            
    if index == 7:
        col.separator()
        col.operator(e, text=text[index], icon_value=icon[index])

in other words how can i add parameter’s for my add light operator call?

To skip menus and run with default arguments, add operator_context and set execution method to EXEC_DEFAULT or EXEC_REGION_WIN.

To add parameters to a button, assign the layout object to a variable and assign operator parameters to it.

layout = self.layout

col = layout.column()
col.operator_context = 'EXEC_REGION_WIN'

op = col.operator("object.light_add", text="Add Light", icon='LIGHT_POINT')

# optional parameters
op.type = 'POINT'
op.radius = 1
op.view_align = False
op.location = 0,0,0
op.rotation = 0,0,0

For loop:

lights = [
    'POINT',
    'SUN',
    'SPOT',
    'AREA'
]

for l in lights:
    op = col.operator("object.light_add", text=l.title(), icon="LIGHT_" + l)
    op.type = l
1 Like