[Solved] Particles - setup and access locations in 2.8

I’m updating one of my plugins to 2.8.
One of the things it does is set up a particle system, then immediately query it for the locations of particles.

The code looks like this:

    bpy.ops.object.particle_system_add()
    psys = obj.particle_systems[-1]  # type: bpy.types.ParticleSystem
    pset = psys.settings
    pset.count = particle_count
    pset.emit_from = emit_from
    pset.distribution = 'RAND'
    pset.use_even_distribution = True

    # Force depsgraph evaluation (https://developer.blender.org/T58792)
    eval_obj = bpy.context.depsgraph.objects.get(obj.name, None)

    # Extract locations
    particles = eval_obj.particle_systems[-1].particles
    locations = [tuple(particle.location) for (index, particle) in particles.items()]

I used to call scene.update(), now I’m calling depsgraph.objects.get to force the particles to be generated.

But it’s not working properly: it always uses the default particle system settings, and ignores the values I set for count and emit_from.

Can anyone explain how deps graph is meant to work?

This is a kind of hacky workaround for now, but have you managed to get it to work by modifying an existing particle system?
The actual handling of the depsgraph and scene updates can come later as UI polish, but I think that modifying an existing particle system should be plenty as a start.

One more thing to note, scene.update still seems to be in the 2.8 Python API, and doesn’t have any indication that it’s been deprecated.
Is there a reason you are trying to use a different method to force the particle system update?

One more thing to note, scene.update still seems to be in the 2.8 Python API, and doesn’t have any indication that it’s been deprecated.

Oh! This was it. I no longer recall what I was thinking in removing it, but thank you, you’ve solved my problem.

BTW I’d actually prefer to modify the existing particle system, but (at least in 2.79), it wasn’t possible to set particle positions.