This sounds really easy but I guess I’m missing something. I just need to make a dropdown menu which displays a list of scene or wm properties. Just looking for the easiest way to store a bunch of random properties in one list or dictionary or whatever and display them in a dropdown menu for quick access. I’ve read several things on here about it and online and failed to grasp what I was reading. Any help, possibly a small example would be appreciated! Thanks.
Use a dynamic EnumProperty: supply a callback-function as items-argument, supply another callback for update to react on changes.
import bpy from itertools import chain class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "scene" def draw(self, context): layout = self.layout layout.prop(context.scene, "dyn_enum") def dyn_items(self, context): return [ ("%s '%s'" % (elem.rna_type.name, elem.name), elem.name, "", 'SCENE' if isinstance(elem, bpy.types.Scene) else 'OBJECT_DATA', i) for i, elem in enumerate(chain(bpy.data.objects, bpy.data.scenes)) ] def upd(self, context): print(self.dyn_enum) def register(): bpy.utils.register_class(HelloWorldPanel) bpy.types.Scene.dyn_enum = bpy.props.EnumProperty(items=dyn_items, update=upd) def unregister(): bpy.utils.unregister_class(HelloWorldPanel) del bpy.types.Scene.dyn_enum if __name__ == "__main__": register()
Thanks for the example code. For some reason it won’t show up until I get rid of the bl_context= “scene” line. I probably should have been a little more clear. This example displays different objects in the display list. I was really more looking for a simple way to house a few scene or general properties (either blender internal properties such as “Use Nodes” or “Simplify” os something along those lines or properties I’ve created such as Integer, String or Boolean types.) Is there a way to just define some specific properties and then have them enum in a dropdown menu? Initially, I was thinking you must need to create a list of the properties you want to show up for this to have them display.
I’ve set something up similar where I just call a menu of the properties I wish to display for quick modification of them, the only problem is when I call the menu from an operator button it does not display inline with the button I created for it. Maybe what I’m looking for is a way to call a menu from a button but have it display in line with the button. I’m just not sure how to do that.
It shows in the scene tab fine here?!
You probably want to create a menu and add it to a panel via layout.menu()
import bpy class SimpleCustomMenu(bpy.types.Menu): bl_label = "Simple Custom Menu" bl_idname = "OBJECT_MT_simple_custom_menu" def draw(self, context): layout = self.layout ob = context.object if ob is not None: layout.prop_menu_enum(ob, "my_enum") layout.prop(ob, "name", text="", icon="GREASEPENCIL") if ob.active_material is not None: layout.prop(ob.active_material, "use_nodes") render = context.scene.render layout.prop(render, "use_simplify") class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object" def draw(self, context): layout = self.layout layout.menu("OBJECT_MT_simple_custom_menu") def register(): bpy.utils.register_module(__name__) bpy.types.Object.my_enum = bpy.props.EnumProperty(items=(('A','A',''),('B','B',''))) def unregister(): bpy.utils.unregister_module(__name__) del bpy.types.Object.my_enum if __name__ == "__main__": register()
Menus are very limited, don’t try to squeeze in fancy features such a layout.split() etc.
You should actually NOT USE ANY containers. If necessary, invoke a popup or dialog. Or just add all your properties straight to a panel.