I have this template_list that lists meshes, but I only want it to list meshes that have custom property named “Datablock”. How can I filter that? Is it even possible?
def filter_items(self, context, data, propname):
bpy_data_meshes = getattr(data, propname)
filter_flags = [0] * len(bpy_data_meshes)
visible = 1 << 30
for i, me in enumerate(bpy_data_meshes):
if "Datablock" in me:
filter_flags[i] = visible
return filter_flags, ()
In your custom ui list define a filter_items method like the above.
Blender expects it to return two things:
A sequence of filter flags. If you have 5 meshes, you need 5 filter flags.
A sequence representing the order for sorting, or empty tuple to use default.
A filter flag for each item will have a value of 1 << 30, which means visible.
Setting a value to zero means the item will not be drawn in the list.