Hi
I’m trying to create a drop down menu in a panel, so far it’s all working, but I need to make the user update the list manually, using an operator.
If I try to update automatically, I get error message that I’m currently in the readonly State. If I use the update function of the emumproperty that works, but ppl. would have to chose their value twice.
Is there a way to call my_update function for the enumProperty as soon as I choose something from a prop_search list?
That would be the ideal solution.
For dynamic values a callback can be passed which returns a list in the same format as the static list. This function must take 2 arguments (self, context) WARNING: There is a known bug with using a callback, Python must keep a reference to the strings returned or Blender will crash.
On the risk of sounding stupid, I don’t know how that helps me…
As far as I got it, the callback of this only updates the list once I choose an item from that list. I need it to be altered by another event, preferably by choosing an item from my prop_search. Or does that work with the get / set.
Could you give me an example? Sorry, sometimes an API is very cryptic to me.
I didn’t see there were examples above the place of your link. I guess get / set is the key here. Problem is: in the example the set just prints something and the get returns an integer. I need the list items to be changed.
If you use UILayout.prop an Enum Property will be displayed as a dropdown list. When the user presses the button the items will be queried from the passed callback function.
I.e.
import bpy
def callback(self, context):
items = [
("#1", "First Item", "", 0),
("#2", "Second Item", "", 1)
]
if context.scene.bool == True:
items.append(("#3", "Third Item", "", 2))
return items
def update(self, context):
#snap back to the first item when scene.bool becomes False
if not context.scene.bool and self['test'] == 2:
self.test = "#1"
bpy.types.Scene.test = bpy.props.EnumProperty(items=callback)
bpy.types.Scene.bool = bpy.props.BoolProperty(update=update)
bpy.context.scene.bool = False
bpy.context.scene.test = "#1"
I have no clue, how you are using EnumProperty with prop_search. Reading the description you will likely have to use a bpy.props.CollectionProperty or any collection which is provided by blender, to search for an item in this collection and assign it to the given data path.
As far as i know there are no subscribable events available.
If you don’t find the api documentation helpful you might try blender.stackexchange.
Ok, getting that bool in there to call the update function is an interesting approach, but I think in my case, I can’t use it. I think I need to be more precise in my description:
I have a UI
I use a prop_search to let the user pick a Node
Once the object is selected a dropdown list appears
The items in the dropdown list is dependent on the item chosen from the prop_search, meaning it will change from Node to Node
I cannot use another prop_search, because I want more items in there than there are attributes to that node.
So if I could call the update() by picking an item from the prop search, that would be ideal.
If I use the update call from the EnumProp I can make it update itself, but I guess this is risky and also the user would have to choose his item twice.
Is there maybe an enum_search or similar? Because the prop_search updates itself dynamically.