0
$\begingroup$

All answers I've seen here before say to check whether an object has multiple users to know if it's instanced or not, but what if you have multiple objects with multiple instances of each?

How do you sort through them in Python?

(What I really want to figure out is how to perform operations in script which are normally forbidden on instances in Blender, but first steps first.)

PS. Not talking about collections here, but objects/meshes!

$\endgroup$
1
$\begingroup$

For all meshes and their instances, you can loop over the mesh objects and collect objects that correspond to the same mesh using a dictionary:

import bpy
from collections import defaultdict

result = defaultdict(list)

for obj in [o for o in bpy.data.objects if o.type == 'MESH']:
    result[obj.data].append(obj)
    
for mesh, objects in result.items():
    print( "Mesh " + mesh.name + " has " + ", ".join(o.name for o in objects) + " object(s) for instance(s)")

Or, to find instances of one mesh:

import bpy

obj = bpy.data.objects['Cube']

instances = [o for o in bpy.data.objects if o.data == obj.data]

print(instances)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.