Yardie
(Yardie)
September 18, 2014, 7:46am
1
Is it possible to create something in python like this (see code below) the following enum setup is done in Blender C code.
What is most interesting to me is a layout with headers.
The icons are not required it’s the columns and headers that I’m interested.
import bpy
class SubMenu(bpy.types.Menu):
bl_idname = "OBJECT_MT_select_submenu"
bl_label = "Select"
def draw(self, context):
layout = self.layout
# expand each operator option into this menu
layout.operator_menu_enum("object.constraint_add", "type", text="Add Constraint" )
bpy.utils.register_class(SubMenu)
# test call to display immediately.
bpy.ops.wm.call_menu(name="OBJECT_MT_select_submenu")
Thanks
Yardie
CoDEmanX
(CoDEmanX)
September 18, 2014, 2:59pm
2
import bpy
class SimpleCustomMenu(bpy.types.Menu):
bl_label = ""
bl_idname = "OBJECT_MT_simple_custom_menu"
def draw(self, context):
layout = self.layout
row = layout.row()
sub = row.column()
sub.label("Generate")
sub.operator("object.modifier_add", text="Array", icon='MOD_ARRAY').type = 'ARRAY'
sub.operator("object.modifier_add", text="Bevel", icon='MOD_BEVEL').type = 'BEVEL'
sub.operator("object.modifier_add", text="Boolean", icon='MOD_BOOLEAN').type = 'BOOLEAN'
sub.operator("object.modifier_add", text="Build", icon='MOD_BUILD').type = 'BUILD'
sub = row.column()
sub.label("Deform")
sub.operator("object.modifier_add", text="Armature", icon='MOD_ARMATURE').type = 'ARMATURE'
sub.operator("object.modifier_add", text="Cast", icon='MOD_CAST').type = 'CAST'
sub.operator("object.modifier_add", text="Curve", icon='MOD_CURVE').type = 'CURVE'
sub.operator("object.modifier_add", text="Displace", icon='MOD_DISPLACE').type = 'DISPLACE'
sub.operator("object.modifier_add", text="Hook", icon='HOOK').type = 'HOOK'
sub.operator("object.modifier_add", text="Laplacian Smooth", icon='MOD_SMOOTH').type = 'LAPLACIANSMOOTH'
def register():
bpy.utils.register_class(SimpleCustomMenu)
def unregister():
bpy.utils.unregister_class(SimpleCustomMenu)
if __name__ == "__main__":
register()
# The menu can also be called from scripts
bpy.ops.wm.call_menu(name=SimpleCustomMenu.bl_idname)
Yardie
(Yardie)
September 18, 2014, 4:26pm
3
AGAIN Thanks heaps CoDEmanX you go way beyond every time.
Pretty icons and all.
I hadn’t realised that you could build a menu just like a dialog.
It should have been obvious I just didn’t think of it.