I´m using a Macro type Operator to concatenate actions which require the user to interact at some points, so I create a Macro Operator class and then populate it with some existing (or custom) Operators, using the define method.
Then I call it from the user interface like some regular operator, except that, (I suppose) I cannot use the user interface to pass arguments to a specific operator inside the Macro, so I want to know which is the right procedure to pass these arguments, because I need the operators to react with different settings than defaults.
I tried to add more arguments to the "define" method during register, but an error is raised declaring that it can only take 2 positional arguments: the idname of the Operator (and I suppose self).
import bpy
class Panel(bpy.types.Panel):
bl_label = "Panel"
bl_idname = "Name"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Tools"
def draw(self, context):
layout = self.layout
layout.row().operator("macro.start")
class Macro(bpy.types.Macro):
bl_idname = "macro.start"
bl_label = "Start Sequence"
class SomeOperator(bpy.types.Operator):
bl_idname = "macro.finish"
bl_label = "Finishing Operator"
def execute(self, context):
# do something else after transform
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
Macro.define("TRANSFORM_OT_translate") # How can I give arguments to an existing Operator?
Macro.define("MACRO_OT_finish")
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
bpy.ops.macro.finish(val=2)
. Getting your head around dynamically generated classes can be hard but try this answer $\endgroup$row.operator("macro.start").TRANSFORM_OT_translate = {"value": (1,0,0)}
, I get the complain that the attributeTRANSFORM_OT_translate
is read-only, while on the other hand if I call the macro operator from normal execution context like thisbpy.ops.macro.start(TRANSFORM_OT_translate={"value": (1,0,0)})
, it works just fine. $\endgroup$