0
$\begingroup$

I'm trying to figure out how to create a drop-down list inside of panel, that has buttons in it, like you see in the image for "Mirror". At the moment, I've already figured out how to add a custom button to this panel with the code bpy.types.VIEW3D_MT_object_context_menu.append(), but now I just need to know how to create a drop-down list.

enter image description here

$\endgroup$
1

1 Answer 1

2
$\begingroup$

You are interested in bpy.types.Menu. Docs: https://docs.blender.org/api/current/bpy.types.Menu.html#bpy.types.Menu

Here is the example of a code needed to create nested menu you have shown:


import bpy

class MT_NestedMenu(bpy.types.Menu):
    bl_idname = "nested.menu"
    bl_label = "Nested Menu"

    # Drawing a nested menu with three operators(buttons)
    def draw(self, context):
        layout = self.layout
        layout.operator('object.some_operator1', text='Button1')
        layout.operator('object.some_operator2', text='Button2')
        layout.operator('object.some_operator3', text='Button3')

# Defining function to append NestedMenu class to the Object Context Menu
def add_to_view3d_mt_object_context_menu(self, context):
    layout = self.layout
    layout.menu('nested.menu', text='Menu')

# Registering/Unregistering
def register():
    bpy.utils.register_class(MT_NestedMenu)
    bpy.types.VIEW3D_MT_object_context_menu.append(add_to_view3d_mt_object_context_menu)

def unregister():
    bpy.utils.unregister_class(MT_NestedMenu)
    bpy.types.VIEW3D_MT_object_context_menu.remove(add_to_view3d_mt_object_context_menu)

if __name__ == "__main__":
    register()

Hope it helps!

$\endgroup$
1
  • $\begingroup$ Worked like a charm! Thank you so much :) $\endgroup$
    – ColinT
    Mar 14, 2023 at 12:36

You must log in to answer this question.

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