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()
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.
Thank you very much! Works great !
if youâre interested
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âŚ