Custom dynamic search_property in prop_search

Hi all,

I’ve been trying to implement a custom search list to be used in a prop_search. Everything works great if I use the ‘built in’ collections, eg:


row.prop_search(context.scene.propsearchtoolsettings, "Group", bpy.data, "groups")

However, I would like to filter this list of groups and, eg, only show groups that have mesh objects in them. This list will obviously change when the scene changes, and the interface should reflect that. I’ve been reading around and everything seems to point at using a collection property, but I can’t seem to make it dynamic. If I try to change the items in the draw() or poll(), I get an error that this is not allowed in that context – see the commented out code for poll() in Panel.py. Fair enough, I guess, but how can I make it so this list is kept up to date?

Here’s what I have so far: propSearchTool.zip (2.32 KB)
It looks like this:


This is the code defining the properties (especially MeshGroup/s):

class MeshName(bpy.types.PropertyGroup):
    name = StringProperty(name = "Name", description = "Name of Mesh object")
  
class PropSearchToolSettings(bpy.types.PropertyGroup):
    Group = StringProperty(name = "Group", description = "Group containing the objects to generate")
    
    MeshGroups = CollectionProperty(type = MeshName)
    MeshGroup = StringProperty(name = "MeshGroup", description = "MeshGroup containing the objects to generate")
    
    Object = StringProperty(name = "Object", description = "Object controlling the initial transformation of the generated object")
    Material = StringProperty(name = "Material", description = "Material to apply to the generated objects")

This is how I would like to use it:

row.prop_search(context.scene.propsearchtoolsettings, "MeshGroup", context.scene.propsearchtoolsettings, "MeshGroups", icon = 'GROUP')

I’d very much appreciate it if someone could give me a little push in the right direction… :slight_smile: