How to make a custom Drop Down menu

Hello, everyone,

I’ve been slowly learning python, but I’m having trouble with drop down menu’s and checkboxes. I can easily duplicate one from the existing UI, but I can’t figure out how to make one from scratch.

Any help would be apprecieated. Thanks in advance.

first you need to create an EnumProperty for a dropdown, and a BoolProperty for a checkbox. Adding them to a panel is the second step.

http://www.blender.org/api/blender_python_api_2_73a_release/bpy.props.html

Hi, thanks for the fast reply.

I already figured out that I need a custom property, I just can’t figure out how I’m supposed to declare it so that the checkbox/drop down gets it.

I quickly wrote a script to make a checkbox that isn’t working. Can you show me what I’m doing wrong so that I can apply it in other area’s?


import bpy
from bpy.types import Menu, Panel, UIList

i = bpy.props.BoolProperty(name="checkbox")

class testpanel(Panel):
    bl_category = "test"
    bl_label = "test"
    bl_context = "objectmode"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    
    def draw(self, context):
        layout = self.layout

        col = layout.column(align=True)
        
        col.prop("checkbox", text="Test")

Thanks!

You need to register properties on an ID type:

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Scene properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "SCENE_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        wm = context.window_manager
        
        layout.prop(wm, "your_prop")

def register():
    bpy.types.WindowManager.your_prop = bpy.props.BoolProperty(name="Your Prop")
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.WindowManager.your_prop

if __name__ == "__main__":
    register()

For UI-only properties, you may use WindowManager (but beware, those won’t be saved in the .blend), or on the appropriate “thing”, like Object, Scene, Bone… these will be saved in .blend.

Thanks, that worked.