0
$\begingroup$

Is it possible to add submenu (from another custom class) in pie menu is a such way as to make it always expanded (without howering over it). Or maybe it possible with popup menu as submenu? (For example, there is “Expand Popup Dialog” checkbox in Pie Menu Editor addon).

And second question is how to insert panels in pie menu? Again, it is possible with Pie Menu Editor but I want to know how do it by myself, without addons.

enter image description here

import bpy
from bpy.types import Menu, Operator

class CUSTOM_MT_menu(Menu):
    bl_label = "Main Menu"
    bl_idname = "CUSTOM_MT_menu"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()

        pie.menu("CUSTOM_MT_submenu", text='SubMenu')
        
        pie.operator("object.custom_operator", text='Operator')
        
        col = pie.column()
        col.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        col.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        col.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        

class CUSTOM_MT_submenu(Menu):
    bl_label = "Sub Menu"
    bl_idname = "CUSTOM_MT_submenu"

    def draw(self, context):
        layout = self.layout        
        
        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        
        
class CUSTOM_OT_operator(Operator):
    bl_idname = "object.custom_operator"
    bl_label = "Operator"
    
    def execute(self, context):
        return {'FINISHED'}

    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self, width=70)

    def draw(self, context):
        layout = self.layout        

        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")
        layout.operator("mesh.primitive_cube_add", text = "Cube", icon = "MESH_CUBE")          


classes = (    
    CUSTOM_MT_menu,
    CUSTOM_MT_submenu,
    CUSTOM_OT_operator
    )

register, unregister = bpy.utils.register_classes_factory(classes)

if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu_pie(name="CUSTOM_MT_menu")
$\endgroup$

1 Answer 1

1
$\begingroup$

All the credit goes to iceythe

discussion thread

If you just want the menu items expanded, just like your manual column of operators:

col1 = pie.column()
col1.menu_contents("CUSTOM_MT_submenu")

Panels, like menus are just draw functions. You can funnel them through any layout. You can use something like this to pass as override layout:

class Layout:
    def __init__(self, layout):
        self.layout = layout

then

col2 = pie.column()
override = Layout(col2)
bpy.types.OBJECT_PT_display.draw(override, context)

context.armature doesn’t exist outside of properties, so you must generate a new context and manually add armature to it.

Good news is, the procedure is same as with the layout override. Adding a check to emulate a poll is a good idea since drawing the panel yourself circumvents the original one. The bad news is, well, there are no bad news.

class Context(dict):
    def __init__(self, context=None, **kwargs):
        super().__init__()
        self.__dict__ = self

        if context is not None:
            self.update(context.copy())
        self.update(**kwargs)

Then draw the armature panel like this:

if context.object.type == 'ARMATURE':
    context_ = Context(context, armature=context.object.data)
    col3 = pie.column()
    override = Layout(col3)
    bpy.types.DATA_PT_display.draw(override, context_)

Custom operators no longer go into bpy.types. Instead you reference the class itself:

col4 = pie.column()
override = Layout(col4)
CUSTOM_OT_operator.draw(override, context)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .