5
$\begingroup$

So I am trying to manipulate the generation of the particle system to something which is predefined. However, when I set the particles location or rotation it is not reflected in the 3D viewport.

My setup is just a simple plane and trying to manipulate the particle system via this code:

bpy.context.active_object.particle_systems['ParticleSystem'].particles[0].location = [5,5,5]

I have tried bpy.context.scene.update() and bpy.context.active_object.particle_systems[0].particles.update() but neither seem to do anything. The python api is responding out correctly, it just isnt reflecting in the viewport. Is there anything else i need to do?

$\endgroup$
  • $\begingroup$ Ok so it seems like it is working but it isnt? if i set it to dupli_object (which is what i am after) but dont set an object there is a point in the correct spot... but when i set a dupli object via the drop down or via python it doesnt generate a dupliobject at the correct spot. $\endgroup$ – Carlo Mar 29 '16 at 23:20
5
$\begingroup$

Got this to work by using the somewhat deprecated and dangerous method for forcing a scene redraw bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1).

enter image description here

import bpy
import numpy as np
from mathutils import Vector

p = bpy.context.active_object.particle_systems['ParticleSystem'].particles

locations = 10 * np.random.random((len(p),3)) - 5
locations = [ Vector(co) for co in locations ]

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

bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1) # <== This is the magic operator
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.