How Use Macro in 2.8?


How Use Macro in 2.8?
I want my script to work for 2.8


Who can give me an example?


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):
        return {'FINISHED'}
class BazOperator(bpy.types.Operator):
    bl_idname =  "wm.baz_operator"
    bl_label = "Baz Operator"
    def execute(self, context):
        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:
def unregister():
    for c in reversed(classes):

if __name__ == "__main__":


Hello! your answer was correct thanks, but I ran into another problem. My macro does not want to call view3d.select_box via hotkey. At that time, if you call it through the search menu, everything works. Maybe you can tell me what the problem is.

Can you tell me how to make OcclusionMacro.define (“view3d.select_lasso”) or OcclusionMacro.define (“view3d.select_box”) called depending on the global variable?


They need to use the fully qualified ‘idname’:

def register():
	global Mode
	global ModS
	for c in classes:
#	#OcclusionMacro.define("view3d.select_lasso")

Macros aren’t flexible with program flow. They don’t have a useful method for this and items in the macro can’t be changed without re-registering the class.

For this maybe it’s better to make a new operator that invokes the appropriate box/lasso depending on the global variable or property. Then use this new operator when you define during registration instead of box/lasso.


Thank you very much! Works great !
if you’re interested