File: bpy.types.Macro.py

package info (click to toggle)
blender 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 329,128 kB
  • sloc: cpp: 2,489,823; python: 349,859; ansic: 261,364; xml: 2,103; sh: 999; javascript: 317; makefile: 193
file content (50 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
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()