4
class CustomMenu(bpy.types.Menu):
5
bl_label = "Custom Menu"
6
bl_idname = "OBJECT_MT_custom_menu"
8
def draw(self, context):
11
layout.operator("wm.open_mainfile")
12
layout.operator("wm.save_as_mainfile").copy = True
14
layout.operator("object.shade_smooth")
16
layout.label(text="Hello world!", icon='WORLD_DATA')
18
# use an operator enum property to populate a sub-menu
19
layout.operator_menu_enum("object.select_by_type",
21
text="Select All by Type...",
25
layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"
28
def draw_item(self, context):
30
layout.menu(CustomMenu.bl_idname)
34
bpy.utils.register_class(CustomMenu)
36
# lets add ourselves to the main header
37
bpy.types.INFO_HT_header.append(draw_item)
41
bpy.utils.unregister_class(CustomMenu)
43
bpy.types.INFO_HT_header.remove(draw_item)
45
if __name__ == "__main__":
48
# The menu can also be called from scripts
49
bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)