4
$\begingroup$

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.

$\endgroup$

2 Answers 2

10
$\begingroup$

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")
$\endgroup$
0
0
$\begingroup$

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 data

With 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:

https://blender.stackexchange.com/a/8712/28015

$\endgroup$
2
  • $\begingroup$ Yeah, using prop_search to find all objects is easy. That's how it works now, but it is confusing for the user. Since I have fogs, liquids, portals and other kinds of objects using custom properties for my model fileformat. 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. blender.stackexchange.com/questions/74453/… Maybe you know how to make it work with dynamic enums or something. $\endgroup$
    – D. Skarn
    Mar 4, 2017 at 13:55
  • $\begingroup$ I see...I think this may be better for one of the developers to answer such as @ideasman42. I may additionally help you out with a bounty, but the question should be edited to become more clear first. $\endgroup$
    – JakeD
    Mar 4, 2017 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .