How to create a drop down menu in bpy

I was creating a custom tool shelf panel for me. You can see it here…

I want to create a drop down menu for some operators…I searched all over the internet. found something 'operator_enum_menu". Tried in different ways, but not getting right…(because of my little knowledge in bpy :)) Here is the code layout what I have now for the drop down menu.


import bpy

class FirstOne(bpy.types.Operator):
bl_idname = “object.first_one_id”
bl_label = “firstonelabel”

def execute(self, context):  
    #---------
    #MAKE THE CUBE BIGGER
    #---------       
    return {'FINISHED'}  

class SecondOne(bpy.types.Operator):
bl_idname = “object.second_one_id”
bl_label = “secondone”

def execute(self, context): 
    #-------
    #MAKE THE CUBE SMALLER---------
    #---------       
    return {'FINISHED'} 

class ThirdOne(bpy.types.Operator):
bl_idname = “object.third_one_id”
bl_label = “thirdone”

def execute(self, context): 
    #--------
    #MAKE THE CUBE A SPHERE---------
    #---------       
    return {'FINISHED'} 
 
                #TOOL PANEL UI

class ToolPanel(bpy.types.Panel):
“”“Creates a Panel in the Object properties window”""
bl_label ---------------
--------ETC---------------

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

#---------------BUTTONS---------------

    #BUTTON FOR THE OPERATOR DROP DOWN MENU
    row = layout.row()
    row.scale_y = 1.2
    row.scale_x = 1.2
    <b>SINGLE BUTTON WHICH SHOWS A DROP DOWN MENU</b> (how to do?:spin:)

def register():
bpy.utils.register_class(ToolPanel)
bpy.utils.register_class(FirstOne)
bpy.utils.register_class(SecondOne)
bpy.utils.register_class(ThirdOne)

def unregister():
bpy.utils.unregister_class(ToolPanel)
bpy.utils.unregister_class(FirstOne)
bpy.utils.unregister_class(SecondOne)
bpy.utils.unregister_class(ThirdOne)

if name == “main”:
register()


I need a drop down menu like the lamp dropdown menu


So I can select one of them.ie. First One , Second One, Third One …
Like this :yes:… Then the function works.ie… making cube bigger or smaller …etc…


…Hope some one will give me solution :frowning:

Did you try the menu templates found in the Text Editor?

I will give it a try… Thanks CodemanX

OK… Thanks guys…

I solved my problem. Both of your answers helped me…
First I tried with menu template…learned something. But the drop down menu did not come in the button where I click…
Then checked in blenderstackexhange, .Got CodemanX answer from here…


got something… Mixed both of the Idea… worked well… Thanks

I added this to my script

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

layout.operator("object.first_one_id")
layout.operator("object.second_one_id")
layout.operator("object.third_one_id")

class SimpleOperator(bpy.types.Operator):
“”“Tooltip”""
bl_idname = “object.simple_operator”
bl_label = “Simple Object Operator”

@classmethod
def poll(cls, context):
    return context.object is not None

def execute(self, context):
    wm = bpy.context.window_manager
    wm.popup_menu(draw_func, title="Options")
    return {'FINISHED'}

-------------------registered the SimpleOperator class in def register and also unregistered
Then added this too to the script for the button.


#NEW BUTTON
col = layout.column()
col.operator(“object.simple_operator”, text=“BUTTON”)

So when I click on my Button a DROP DOWN MENU appears. What a joyful moment !!!
THANKS!!!

It’s an amazing moment isn’t it?

Of course! it is an amazing moment :slight_smile: