How Use Macro in 2.8?


#1

How Use Macro in 2.8?
I want my script to work for 2.8
https://pastebin.com/BmYH6wVX


#2

Who can give me an example?


#3

You can register an empty Macro first, then define the operators during registration.

Here’s an example with 2 operators in script plus an internal operator. This will print “Hello” and “World” from each operator, and select all objects using the idname of bpy.ops.object.select_all().

import bpy

class BarOperator(bpy.types.Operator):
    bl_idname =  "wm.bar_operator"
    bl_label = "Bar Operator"

    def execute(self, context):
        print("Hello")
        return {'FINISHED'}
        
class BazOperator(bpy.types.Operator):
    bl_idname =  "wm.baz_operator"
    bl_label = "Baz Operator"
    
    def execute(self, context):
        print("World")
        return {'FINISHED'}
        
class FooMacro(bpy.types.Macro): # <<- empty macro
    bl_idname = "wm.foo_macro"
    bl_label = "Foo Macro"

classes = (BarOperator, BazOperator, FooMacro)
    
def register():
    for c in classes:
        bpy.utils.register_class(c)
    FooMacro.define("WM_OT_bar_operator")
    FooMacro.define("WM_OT_baz_operator")
    FooMacro.define("OBJECT_OT_select_all")
    
def unregister():
    for c in reversed(classes):
        bpy.utils.unregister_class(c)

if __name__ == "__main__":
    register()