Following this example I added a psys to my scene. I add the cube from the script because for this application I CAN NOT use the GUI, so adding this snippet:
bpy.ops.mesh.primitive_cube_add(size=0.25, calc_uvs=True, enter_editmode=False, align='WORLD',
location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0))
bpy.context.active_object.name = 'Cube'
def particleSetter(self):
particle_systems = object.evaluated_get(degp).particle_systems
particles = particle_systems[0].particles
totalParticles = len(particles)
scene = bpy.context.scene
cFrame = scene.frame_current
sFrame = scene.frame_start
# at start-frame, clear the particle cache
if cFrame == sFrame:
psSeed = object.particle_systems[0].seed
object.particle_systems[0].seed = psSeed
# Rotate particles based on index (t_p) and frame (t_f)
t_p = np.linspace(0, 2*np.pi, totalParticles, endpoint=False)
t_f = cFrame / 20.0
data = np.array([np.sin(t_p + t_f), np.cos(t_p + t_f), np.zeros(t_p.shape)]).T
flatList = data.ravel()
# Set the location of all particle locations to flatList
particles.foreach_set("location", flatList)
Prepare particle system
object = bpy.data.objects["Cube"]
object.modifiers.new("ParticleSystem", 'PARTICLE_SYSTEM')
object.particle_systems[0].settings.count = 10
object.particle_systems[0].settings.frame_start = 1
object.particle_systems[0].settings.frame_end = 1
object.particle_systems[0].settings.lifetime = 1000
object.show_instancer_for_viewport = False
degp = bpy.context.evaluated_depsgraph_get()
#clear the post frame handler
bpy.app.handlers.frame_change_post.clear()
#run the function on each frame
bpy.app.handlers.frame_change_post.append(particleSetter)
Update to a frame where particles are updated
bpy.context.scene.frame_current = 2
I would expect to see particles, but nothing is shown in the render. Also, if I set
object.particle_systems[0].settings.type = 'HAIR'
I see the spikes, but I want particles that whose location can be specified, not just spikes on a surface. Whant am I doing wrong?
Edit: I tried to specify the object instantiation, still no effect:
bpy.ops.mesh.primitive_cube_add(size=0.25, calc_uvs=True, enter_editmode=False, align='WORLD',
location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0))
bpy.context.active_object.name = 'Cube'
context = bpy.context
dg = context.evaluated_depsgraph_get()
ob = dg.objects.get("Cube")
ob.modifiers.new("ParticleSystem", 'PARTICLE_SYSTEM')
ps = ob.particle_systems.active
ps.settings.render_type = "OBJECT"
ps.settings.display_method = "RENDER"
ps.settings.instance_object = ob
po = ps.settings.instance_object
for p in ps.particles:
p.location = (5*np.random.rand(), 5*np.random.rand(), 5*np.random.rand())
bpy.context.view_layer.update()
scene and depsgraph. (IMO do not mix context with handlers, the evaluated object in this case isobj = depsgraph.objects.get("Cube")Later on speculates render anim with render still + frame set. Related https://blender.stackexchange.com/questions/142741/how-do-i-programmatically-set-hair-position-and-shape-in-blender-2-8` – batFINGER Jun 29 '21 at 17:13