Hi and thanks for the code snippet!
It does seem to work great for getting the particle locations. However, in my current situation I need to be able to set particle locations and that does not work with foreach_set("location", flatList)
(using most recent Blender 2.80 build on Windows).
Here’s an example (using initial scene with a particle system of 3 particles on the Cube-object):
import bpy
# --- PASS 1 ---
degp = bpy.context.evaluated_depsgraph_get()
object = bpy.data.objects["Cube"]
particle_systems = object.evaluated_get(degp).particle_systems
particles = particle_systems[0].particles
totalParticles = len(particles)
flatList = [0]*(3*totalParticles)
# additionally set the location of all particle locations to [0, 0, 0]
particles.foreach_set("location", flatList)
# ... and confirm they are set as intended
particles.foreach_get("location", flatList)
print('PASS 1: {}'.format(flatList))
# --- Toggle back and forth to update viewport ---
bpy.ops.particle.particle_edit_toggle()
bpy.ops.particle.particle_edit_toggle()
# --- PASS 2 ---
degp = bpy.context.evaluated_depsgraph_get()
object = bpy.data.objects["Cube"]
particle_systems = object.evaluated_get(degp).particle_systems
particles = particle_systems[0].particles
totalParticles = len(particles)
flatList = [0]*(3*totalParticles)
particles.foreach_get("location", flatList)
print('PASS 2: {}'.format(flatList))
Expected output: all particles remain at [0, 0, 0]. Actual output:
PASS 1: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
PASS 2: [-0.84..., -1.03..., 0.75..., -1.0, -0.32..., 0.12..., -0.62..., 0.99..., 0.63...]
I don’t know anything about the depsgraph and such, but I’d very much like to find a way to set particle locations by script. Is there another way or a workaround?