In Blender 2.7 it was possible to set particle locations dynamically as demonstrated in this answer.

In 2.8 particle data isn't up to date unless evaluating the emitter via the depsgraph as shown in this bug report.

This does provide up to date data about the number of particles and makes the individual particle location accessible, however trying to set this value does not update the view and seems to have no visible effect, although accessing the same particle location shows a change has been made.

In 2.7 we were able to force a scene redraw to fix this, any way to update the depsgraph or anything similar to manifest these changes?

Here's the code snippet I'm trying to get to work (requires adding a cube object named 'Cube' with a particle system that has a particle count of 50):

import bpy
import numpy as np
from mathutils import Vector

p = bpy.context.depsgraph.objects.get('Cube', None).particle_systems[0].particles

locations = np.random.randint(-10,10,size = (50,3))
locations = [ Vector(co) for co in locations ]

for pp, loc in zip( p, locations ):
    pp.location = loc

# None of this works

1 Answer 1



In answering Get particle location using python came across this one.

Note this will work with instanced object or collection particles. Not those rendered as halo.

Test script, set object with ps as active. Sets all particles on current frame to location (1, 1, 1)

import bpy
from mathutils import Matrix

context = bpy.context

dg = context.evaluated_depsgraph_get()
ob = context.object.evaluated_get(dg)

ps = ob.particle_systems.active
po = ps.settings.instance_object

for p in ps.particles:
    p.location = (1, 1, 1)
  • $\begingroup$ I'm currently getting this error: AttributeError: 'Context' object has no attribute 'evaluated_depsgraph_get' Blendfile: blend-exchange.giantcowfilms.com/b/6186 $\endgroup$
    – TLousky
    Jun 26, 2019 at 12:44
  • $\begingroup$ Need version later than whence scene.update() was replaced. Can confirm it works in 2.80.74. $\endgroup$
    – batFINGER
    Jun 26, 2019 at 12:50
  • $\begingroup$ Downloaded the latest build from builder.blender.org/download (from June 26, 2019). Now the script doesn't pop an exception, but the particle locations aren't affected either... anything else I'm missing? $\endgroup$
    – TLousky
    Jun 26, 2019 at 13:12
  • $\begingroup$ DL'd file Oops didn't check with halo render.. ... works ok with object or collection instancing. better edit in $\endgroup$
    – batFINGER
    Jun 26, 2019 at 13:16
  • $\begingroup$ Nice, indeed works well with objects, cheers! $\endgroup$
    – TLousky
    Jun 26, 2019 at 13:46

You must log in to answer this question.

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