So I understand how this code snippet works, I actually stumbled across the same stack exchange post when I was trying to make my list dynamic. I was able to make it work this in print statements in the console, but I wasn’t able to draw that list in a dropdown menu with selections.
In this example the start of your the enum list is defined as items = []
and in the solution provided by @anon72338821 I see it is defined in a property group. This is the solution I think i need as I want to pass the input to an operator.
I also want the list to dynamically change depending on the context of what is selected.
So if I defined my enum similar to this
class TemplProperties(bpy.types.PropertyGroup):
proplist : bpy.props.EnumProperty(name = "proplist", items = ( )
bpy.types.Object.customprops= bpy.props.PointerProperty(type=TemplProperties)
So in the example you provided they are using items.append
So I tried something similar to:
class MyPanel(bpy.types.Panel):
def draw(self, context):
obj = bpy.context.object
props = obj.customprops.bl_rna.properties["proplist"]
bone_path = obj.pose.bones["bone-name"]
for y, x in bone_path.items():
props.append(f"{y}", f"{y}", f"{y}")
enum = items[props.proplist]
Now when test this code line by line in the blender python console I get this error
AttributeError: 'EnumProperty' object has no attribute 'append'
So I assume .append
doesn’t work for enum props, or my syntax is bad. In the doc I was able to find a set
function in the enum docs. So its my usage that is wrong.
Based on my reading from the docs what I think I need to do is: I need to create a new operator similar to .append
give variables to my enum prop for me and then call that operator in my FOR statement. Which i what I meant by custom getter/setter.
I did some research and found this post Add/remove EnumProperty items? - Coding / Python Support - Blender Artists Community which clearly explained the disconnect I have with this quote
So essentially I have my iterable variable in my bone_path
I have my Enum prop in my group I am only not understanding the some function to generate the enum items.
Will do more reading when I can, i think the solution is in that post i just linked so i just need to break it down for myself.