Hi, I’m new to blender scripting, so bear with me (and my english).
I’m trying to code an interface popup dialog which has an EnumProperty to it. That works just fine. Now the problem is that my EnumProperty has several hundred items, most of which can not be seen on screen. Scrolling doesn’t work. I would need something like the file selector to select the items of the list. Can that be done? Is it even clear what I want to do?
Ok, I got it working in a panel. However, when in a popup dialog, the display just hangs. No scrolling possible. Am I doing something wrong here or is it a bug? Here 's the code:
import bpy
import xml.etree.ElementTree as etree
class thing(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name = "Item", default = "test")
class thinglist(bpy.types.UIList):
bl_idname = "listthings"
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
layout.label(item.name)
class DialogOperator(bpy.types.Operator):
"""Creates a popup dialog"""
bl_label = "My Panel"
bl_idname = "object.dialog_operator"
def draw(self, context):
layout = self.layout
layout.template_list("listthings", "", context.scene, "things", context.scene, "active_thing")
layout.template_list("listthings", "compact", context.scene, "things",
context.scene, "active_thing", type='COMPACT')
def execute(self, context):
print(context.scene.active_thing)
return {'FINISHED'}
def invoke(self,context, event):
return context.window_manager.invoke_props_dialog(self,width = 600, height = 400)
def register():
bpy.utils.register_class(DialogOperator)
bpy.utils.register_class(thing)
bpy.utils.register_class(thinglist)
bpy.types.Scene.things = bpy.props.CollectionProperty(type = thing)
bpy.types.Scene.active_thing = bpy.props.IntProperty(default = 0, min = 0)
def unregister():
bpy.utils.unregister_class(DialogOperator)
bpy.utils.unregister_class(thing)
bpy.utils.unregister_class(thinglist)
del bpy.types.Scene.things
del bpy.types.Scene.active_thing
if __name__ == "__main__":
register()
modeldef = "D:\\example.xml"
tree = etree.parse(modeldef)
root = tree.getroot()
bpy.context.scene.things.clear()
for anim in root:
if anim.tag == 'Animation':
item = bpy.context.scene.things.add()
item.name = anim.attrib['name']
# test call
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
Thanks again for your valuable input, to both of you. I will now investigate CoDEmanX’s suggestion.