3
$\begingroup$

If particle system uses Collection as particles in the Render tab of the Particle System settings is there a way to get exact object which each particle is assigned to via bpy? I know that other particles attributes can be obtained with the depsgraph, e.g.:

import bpy

emitter = bpy.context.object  # assuming it is a particle emitter
dg = bpy.context.evaluated_depsgraph_get()
eval_emitter = emitter.evaluated_get(dg)
for ps in eval_emitter.particle_systems:
    for p in ps.particles:
        print(p.location)

But I can not find anything related to which object is assigned to particular particle among the particle attributes. Is there a way to get this info directly from the particles or maybe to somehow reproduce exact random distribution of which object is used as an instance for which particle?

$\endgroup$
0

1 Answer 1

4
$\begingroup$

This script lists the evaluated instances, which correspond to a particle system, giving the ps name, original object name and particle location.

import bpy

dg = bpy.context.evaluated_depsgraph_get()

for o in dg.object_instances:
    if o.particle_system:
        print(o.particle_system.name, \
            o.instance_object.name, \
            o.matrix_world.translation)
        

Output

ParticleSystem Sphere <Vector (-0.1024, -0.4825, 0.0000)>
ParticleSystem Cube <Vector (-0.4588, 0.2148, 0.0000)>
ParticleSystem Cube <Vector (-0.2058, -0.0513, 0.0000)>
ParticleSystem Cube <Vector (-0.8368, 0.3390, 0.0000)>
ParticleSystem Cube <Vector (0.5467, 0.7251, 0.0000)>
ParticleSystem Cube <Vector (-0.0770, -0.9534, 0.0000)>
ParticleSystem Sphere <Vector (0.8253, -0.9243, 0.0000)>
ParticleSystem Cube <Vector (0.5836, -0.0743, 0.0000)>
ParticleSystem Cube <Vector (0.2153, 0.2062, 0.0000)>
ParticleSystem Sphere <Vector (-0.4823, -0.7403, 0.0000)>
$\endgroup$
1
  • 1
    $\begingroup$ Thank you! Taking object instances and their settings directly from the depsgraph seems to be even more useful than iterating through particle systems! $\endgroup$ Mar 24, 2023 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .