I have a file with many (1000+) objects/instances, many of which are duplicates.
To organize my project I want to split single and multi user objects.
How do I select all objects that are not single user / that are multi-user
I have a file with many (1000+) objects/instances, many of which are duplicates.
To organize my project I want to split single and multi user objects.
How do I select all objects that are not single user / that are multi-user
You can try something like this
import bpy
user_map = bpy.data.user_map()
bpy.context.view_layer.objects.active = None
for obj in bpy.context.selectable_objects:
obj.select_set(False)
# selectable_objects_users = [o for o in user_map.get(obj.data) if isinstance(o, bpy.types.Object) and o in bpy.context.selectable_objects]
objects_users = [o for o in user_map.get(obj.data) if isinstance(o, bpy.types.Object)]
if len(objects_users) > 1:
obj.select_set(True)
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
Get the dictionary mapping of all data blocks with user_map
Traverse all objects (or selectable objects, depends on if you want to find all linked objects in the file or in your selection
If the dictionary mapping of the mesh contains more than one object, the mesh is linked, select the object.
You can optimise this by selecting all the objects after the if
statement and removing the selected objects from the test pool, but I don't think you'll gain much time. Unless you have hundreds of thousands of object, in which case you probably shouldn't try selecting them :)