If a particle system uses a collection with different meshes as its source, we can use the Blender Python API to determine which object is the source of each particle.
To access particles in their current state, we first need to “calculate” the scene – get its “evaluated” version, in which all effects and modifiers are applied to all objects, including particles. This could be done using depsgraph.
1 |
dg = bpy.context.evaluated_depsgraph_get() |
From the evaluated depshgraph we can get a list of scene instances, which are also objects of the particle system.
1 |
psi = (p for p in dg.object_instances if p.particle_system) |
We need to define it in the form of an iterator so as not to change the state of the objects in it.
Now we can, by going through the particles from iterator, show the object – the source of the current particle with coordinates of the particle in the scene.
1 2 3 4 5 6 7 8 9 |
for particle in psi: print( particle.instance_object, particle.matrix_world.translation ) # <bpy_struct, Object("Suzanne") at 0x000001CA5E174F08, evaluated> Suzanne <Vector (8.3390, -0.5906, -1.7259)> # <bpy_struct, Object("Torus") at 0x000001CA5DFC4808, evaluated> Torus <Vector (6.8404, -0.6114, -0.8238)> # ... |