Macro(bpy_struct)
Example Macro
This example creates a simple macro operator that moves the active object and then rotates it. It demonstrates:
Defining a macro operator class.
Registering it and defining sub-operators.
Setting property values for each step.
import bpy
class OBJECT_OT_simple_macro(bpy.types.Macro):
bl_idname = "object.simple_macro"
bl_label = "Simple Transform Macro"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object is not None
def register():
bpy.utils.register_class(OBJECT_OT_simple_macro)
# Define steps after registration and set operator values via .properties
step = OBJECT_OT_simple_macro.define("transform.translate")
props = step.properties
props.value = (1.0, 0.0, 0.0)
props.constraint_axis = (True, False, False)
step = OBJECT_OT_simple_macro.define("transform.rotate")
props = step.properties
props.value = 0.785398 # 45 degrees in radians
props.orient_axis = 'Z'
def unregister():
bpy.utils.unregister_class(OBJECT_OT_simple_macro)
if __name__ == "__main__":
register()
# To run the macro:
bpy.ops.object.simple_macro()
base class — bpy_struct
- class bpy.types.Macro(bpy_struct)
Storage of a macro operator being executed, or registered after execution
- bl_cursor_pending
Cursor to use when waiting for the user to select a location to activate the operator (when
bl_optionshasDEPENDS_ON_CURSORset) (default'DEFAULT')- Type:
Literal[Window Cursor Items]
- bl_description
(default “”, never None)
- Type:
str
- bl_idname
(default “”, never None)
- Type:
str
- bl_label
(default “”, never None)
- Type:
str
- bl_options
Options for this operator type (default set())
- Type:
set[Literal[Operator Type Flag Items]]
- bl_translation_context
(default “Operator”, never None)
- Type:
str
- bl_undo_group
(default “”, never None)
- Type:
str
- has_reports
Operator has a set of reports (warnings and errors) from last execution (default False, readonly)
- Type:
bool
- name
(default “”, readonly, never None)
- Type:
str
- properties
(readonly, never None)
- Type:
- report(type, message)
report
- Parameters:
type (set[Literal[Wm Report Items]]) – Type
message (str) – Report Message, (never None)
- classmethod poll(context)
Test if the operator can be called or not
- Parameters:
context (
Context) – (never None)- Return type:
bool
- classmethod define(operator)
Append an operator to a registered macro class.
- Parameters:
operator (str) – Identifier of the operator. This does not have to be defined when this function is called.
- Returns:
The operator macro for property access.
- Return type:
- classmethod bl_rna_get_subclass(id, default=None, /)
- Parameters:
id (str) – The RNA type identifier.
default (
bpy.types.Struct| None) – The value to return when not found.
- Returns:
The RNA type or default when not found.
- Return type:
- classmethod bl_rna_get_subclass_py(id, default=None, /)
- Parameters:
id (str) – The RNA type identifier.
default (type | None) – The value to return when not found.
- Returns:
The class or default when not found.
- Return type:
type