2.8 getting particle attributes


(Jakub Vondra) #1

Hello,
In 2.79 this would get me an array with location of particles on selected objects:

import bpy
for psys in bpy.context.active_object.particle_systems:  
   par_loc = [0,0,0]*len(psys.particles) #create array to store postions 
   psys.particles.foreach_get("location", par_loc) #fill the par_loc array with particle positions
   print(par_loc)

In 2.80 this no longer works, it just returns an empty array. I’ve checked the 2.80 api and found no reason why this should’t work. (https://docs.blender.org/api/blender2.8/bpy.types.bpy_prop_collection.html#bpy.types.bpy_prop_collection)
Would anyone know what could I be doing wrong? is there any other way to access particle attributes in 2.80 which works for you?
Thanks a lot!


(AFWS) #2

Looks like it returns 0 for particles. Run in 2.79 and then 2.80.

import bpy
for psys in bpy.context.active_object.particle_systems:  
   print(len(psys.particles))

Looks like it has been reported.
https://developer.blender.org/T58792


(Jakub Vondra) #3

Yup, seems psys.particles does not return anything. So probably a bug ?


(AFWS) #4

Check my edit just now, LOL. Looks like a bug that has been reported.


(Jakub Vondra) #5

Awesome thanks! the solution there seems to fix this :slight_smile:
this works in 2.80:

import bpy
ob = bpy.context.active_object
eval_ob = bpy.context.depsgraph.objects.get(ob.name, None)
for psys in eval_ob.particle_systems:
    par_loc = [0,0,0]*len(psys.particles) #create array to store postions 
    psys.particles.foreach_get("location", par_loc) #fill the par_loc array with particle positions
    print(par_loc)