How to List Existing Armatures in Panel

Hi all :),

I’m a beginner python and blender programmer. Right now I’m having a dilemma on how to:

  1. list existing armatures in the current scene?
  2. put the list into the UI Panel via drop-down box?
  3. select an armature through said drop-down box?

Basically, I want to create the ability to see all existing armatures and select either one from a drop down box in the UI panel. So far, I can create the list and the drop-down box but separately. If I try to add the list into the panel, Blender gives me an error. Can anyone shed some light? :smiley:

Also, is it possible to update the drop-down box panel in real-time automatically? (eg: a new armature is created, and is automatically listed and shown in the UI panel)

Thanks in advance!

this should help


import bpy
scn = bpy.context.scene

bpy.types.Scene.OOB = bpy.props.StringProperty()

class OBJECT_PT_oblist(bpy.types.Panel):
    bl_label = "ArmList"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_context = "objectmode"

    def draw(self, context):
        scn = context.scene
        layout = self.layout
        col = layout.column()        
        col.label('list of armatures')
        col.prop_search(scn, "OOB",  bpy.data, "armatures")
        
def register():
    bpy.utils.register_class(OBJECT_PT_oblist)

def unregister():
    bpy.utils.unregister_class(OBJECT_PT_oblist)

if __name__ == "__main__":
    register()

@teldredge
Thanks a lot for the help! That has swiftly solved the drop-down box issue :smiley: A couple of beginner’s questions though:

  1. what does
bpy.types.Scene.OOB = bpy.props.StringProperty()

exactly do? I figured it’s creating a custom property of parent type String, but why from bpy.types.Scene?

  1. so col.prop_search actively search for “armature” types in all data (bpy.data) in the current scene (scn), is that correct? What does “OOB” do in the parameter?

  2. Does bpy.data.objects normally display different naming than bpy.data.armatures? How can I synch the naming between the two?

@sad_katz

  1. doesn’t really do anything in the code example, but could be used to contain the selected armatures name for later use in your script.

  2. see this api doc

  3. this dropdown lists the armatures, not the objects that contain the armatures. So you want a list of all the objects that are armatures- hmm, I’ll have to think about that…

I have read the api documentation, but could not understand what it means by “identifier property in data”. Does that mean the property that prop_search is using “OOB” which could be a list of string?

So, is there currently no way by Blender to synch the object and armature names? How about checking which objects are armatures and display only those?

I’m still learning and working on this and will update if I found anything else.

EDIT:
How about filtering a list of objects that are armatures, then store them into “OOB” before passing into prop_search()?

Well, since the original question is already answered, I’ll mark the thread as [SOLVED] and move the later question in a new thread. Thx for the help! :slight_smile: