"Dynamic" GUI Enum visualization (and values retrieving) problem...

Hello everyone,
I’m working on an Add-On and I have to “dynamically” display, in my GUI (in the Properties Window - Scene context) a set of EnumProperties, based on meshes that are in the scene (the user can choose, for every mesh, an operation to be performed; there are 5 choices so I need a row for every mesh in the scene with an EnumProperty, so the user can choose the operation to be performed on that mesh).

I can’t figure out how to:

  1. create, in the draw function of the Panel, a EnumProperty, with a unique (and retrievable) name, for every mesh in the Scene;
  2. retrieve the value of that Enum, for every Enum in the Panel.

I’m sorry for my bad English, if you want I can provide an extensive description to better explain the problem… thank you very much!! :wink:

  1. is a simple for loop. For 2), I would advise to avoid RNA and use prop(getter, setter) instead. You could also study the code of existing add-ons, see how they do it.
bpy.types.Mesh.your_enum = EnumProperty(...)

for ob in bpy.context.scene.objects:
    if ob.type == 'MESH':

But I can’t see a real reason to give every mesh its own enumprop, if all you want is a dropdown menu with 5 entries…

You should rather use one operator, and accept a mesh name as stringprop and run the operation on the specified mesh datablock.

You would then add that operator as often as you got meshes, e.g. like:

for ob in bpy.context.scene.objects:
    if ob.type == 'MESH':
        prop = layout.operator("your.operator", text=ob.data.name)
        prop.mesh_name = ob.data.name

Thank you very much! :wink: