I would like to be able to pass aarguments to operators that I am calling from panels/buttons but I do not know how to do that. At the moment I use "global" variables but they tend to make the code a bit like a puzzle since I need to constantly update them.
See the code below, in that example I would like to pass an argument (like ARG) to "object.simple_operator" when the button is clicked.
import bpy
def DO_SOMETHING(arg):
print(arg)
return
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
DO_SOMETHING(ARG)
return {'FINISHED'}
class MyPanel(bpy.types.Panel):
bl_label = "mypanel"
bl_idname = "OBJECT_PT_MyPanel"
def draw(self, context):
layout = self.layout
wm = context.window_manager
obj = context.object
row = layout.row()
row.operator('object.simple_operator')
layout.operator("some.op").x = 5
to set the property to 5 (akin tobpy.ops.some.op(x=5)
) For multipleop = layout.op...
op.x = 5
op.string = "XXXX"
$\endgroup$