Is it possible to somehow search all objects on the scene which have a custom property enabled using prop_search?
I know how to do this with dynamic EnumProperty but it seems to be not an option as it has some bugs.
Is it possible to somehow search all objects on the scene which have a custom property enabled using prop_search?
I know how to do this with dynamic EnumProperty but it seems to be not an option as it has some bugs.
Since Blender 2.79 this possible by using bpy.props.PointerProperty and its poll parameter.
For example:
# define the filter method
def filter_on_custom_prop(self, object):
return "MyCustomPropName" in object
# define the property by using the bpy.props.PointerProperty and its poll function
bpy.types.Object.my_object = bpy.props.PointerProperty(
type=bpy.types.Object,
poll=filter_on_custom_prop
)
# add to your draw code a `prop_search`
layout.prop_search(obj, "my_object", context.scene, "objects")
# or just simple
layout.prop(obj, "my_object")
After looking at the API, it doesn't appear to be possible.
From the API:
prop_search(data, property, search_data, search_property, text="", text_ctxt="", translate=True, icon='NONE')
data and property are the same as with a normal property. This may be like bpy.context.scene and "my_prop_name" respectively.
search_data is the data to search in for the "property"
search_property is the property to look for in the dataWith regards to the last two, it would be, e.g., bpy.data and "objects" respectively.
I think a filtering technique like this would be better suited to the examples that @CoDEmanX shows in this answer:
I tried doing it with dynamic enum property using a callback... but the issue is that it does not memorize the item it has selected. So, if a list changes and items move in it, the order gets messed up.
http://blender.stackexchange.com/questions/74453/enumproperty-fill-dynamically-using-callback
Maybe you know how to make it work with dynamic enums or something.
– D. Skarn Mar 04 '17 at 13:55