I’ve used RickyBlender’s script to do this
Is this correct or is there another way to funnel many into one function call with an arg?
import bpy
def do_something(s):
print("DOING:", s)
# ########## FUNCTION STUBS ###########
sprefix = "mesh.primitive_HELLO_add_"
class menu_func_00_00(bpy.types.Operator):
bl_idname = sprefix+"00_00"
bl_label = "Add menu_func_00_00 "
bl_options = {'REGISTER', 'UNDO','BLOCKING'}
def execute(self, context):
do_something("hello from 00 00")
return {'FINISHED'}
class menu_func_00_01(bpy.types.Operator):
bl_idname = sprefix+"00_01"
bl_label = "Add menu_func_00_01 "
bl_options = {'REGISTER', 'UNDO','BLOCKING'}
def execute(self, context):
do_something("hello from 00 01")
return {'FINISHED'}
class menu_func_01_00(bpy.types.Operator):
bl_idname = sprefix+"01_00"
bl_label = "Add menu_func_01_00 "
bl_options = {'REGISTER', 'UNDO','BLOCKING'}
def execute(self, context):
do_something("hello from 01 00")
return {'FINISHED'}
class menu_func_01_01(bpy.types.Operator):
bl_idname = sprefix+"01_01"
bl_label = "Add menu_func_01_01 "
bl_options = {'REGISTER', 'UNDO','BLOCKING'}
def execute(self, context):
do_something("hello from 01 01")
return {'FINISHED'}
# ########## SUB MENUS ###########
class sub_menu_one(bpy.types.Menu):
bl_idname = "sub_menu_one"
bl_label = "experimental menu"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator(menu_func_00_00.bl_idname, text = "func 00 00")
layout.operator(menu_func_00_01.bl_idname, text = "func 00 01")
class sub_menu_two(bpy.types.Menu):
bl_idname = "sub_menu_two"
bl_label = "experimental menu"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator(menu_func_01_00.bl_idname, text = "func 01 00")
layout.operator(menu_func_01_01.bl_idname, text = "func 01 01")
# ########## MAIN MENU ###########
class menu_main(bpy.types.Menu):
# PRIMARY MENU
bl_idname = "menu_main"
bl_label = "My Title"
def draw(self,context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.menu(sub_menu_one.bl_idname, text = "one")
layout.menu(sub_menu_two.bl_idname, text = "two")
# ########## GUBBINS ###########
def menu_func(self, context):
self.layout.menu(menu_main.bl_idname, icon="PLUGIN")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_mesh_add.append(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_mesh_add.remove(menu_func)
if __name__ == "__main__":
register()