ui_menu.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import bpy
  2. class CustomMenu(bpy.types.Menu):
  3. bl_label = "Custom Menu"
  4. bl_idname = "OBJECT_MT_custom_menu"
  5. def draw(self, context):
  6. layout = self.layout
  7. layout.operator("wm.open_mainfile")
  8. layout.operator("wm.save_as_mainfile").copy = True
  9. layout.operator("object.shade_smooth")
  10. layout.label(text="Hello world!", icon='WORLD_DATA')
  11. # use an operator enum property to populate a sub-menu
  12. layout.operator_menu_enum("object.select_by_type",
  13. property="type",
  14. text="Select All by Type...",
  15. )
  16. # call another menu
  17. layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"
  18. def draw_item(self, context):
  19. layout = self.layout
  20. layout.menu(CustomMenu.bl_idname)
  21. def register():
  22. bpy.utils.register_class(CustomMenu)
  23. # lets add ourselves to the main header
  24. bpy.types.INFO_HT_header.append(draw_item)
  25. def unregister():
  26. bpy.utils.unregister_class(CustomMenu)
  27. bpy.types.INFO_HT_header.remove(draw_item)
  28. if __name__ == "__main__":
  29. register()
  30. # The menu can also be called from scripts
  31. bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)