How Use Macro in 2.8?

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

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):
        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()
5 Likes

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.
Code https://github.com/Darcvizer/Border-Occlusion/blob/master/BorderOcclusion28.py

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:
		bpy.utils.register_class(c)
	OcclusionMacro.define("VIEW3D_OT_border_on")
#	#OcclusionMacro.define("view3d.select_lasso")
	OcclusionMacro.define("VIEW3D_OT_select_box")
	OcclusionMacro.define('VIEW3D_OT_border_off')

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.

2 Likes

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

1 Like

Thanks! I got this to work… although not what I hoped.

Trying to see if it’s even possible to call a modal operator, then when I click the left mouse/commit, it goes into another operator, that’s running as normal. Normal as in, my stand alone operator is “looping”, so that I can change my sliders/settings and the mesh resets/updates.

But right now, in the modal, it’s not going to work as I hoped, and calling my operator from the Modal, it loops once, then finishes/doesn’t keep running…