0
$\begingroup$

I have an object in my scene named cube. Is it possible to add a particle system to that object with python by using its name?

$\endgroup$
  • $\begingroup$ I've provided an answer for you with script, screenshots and a .blend file $\endgroup$ – Tak Jan 13 '17 at 2:35
0
$\begingroup$

Yes. Objects are in the datablock bpy.data.objects:

obj = bpy.data.objects['Cube']
particles = obj.modifiers.new("myparticles", type="PARTICLE_SYSTEM")

#once you have the modifier, you can adjust its settings
particles.particle_system.settings.particle_size = 1.0
#and other properties
particles.particle_system.vertex_group_density = mygroup

More info: ParticleSystem ParticleSettings

$\endgroup$
  • $\begingroup$ Also how would I add more settings to this particle system? $\endgroup$ – user32399 Jan 13 '17 at 2:42
  • $\begingroup$ Added more info to answer. $\endgroup$ – cmomoney Jan 13 '17 at 2:52
1
$\begingroup$

You can do this using the below script:

import bpy

C= bpy.context
scene = C.scene

bpy.ops.object.select_all(action='DESELECT')
objname = 'Cube' ###### Add Name of object you want here ######
ob = bpy.data.objects[objname]
ob.select = True
scene.objects.active = ob
bpy.ops.object.particle_system_add()

Result:

enter image description here

A .blend file can be downloaded from here:

$\endgroup$

Your Answer

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