What I am trying to do is create a plane and add a particle system to the plane.
Once again, bpy.ops is my enemy. It works fine in top down scripting, but when I try to use it in an operator, the context comes from the caller of the operator, in my case this happens to be an Empty.
This code works fine in top-down processing. Paste it into a code window and run it.
import bpy bpy.ops.mesh.primitive_plane_add(location=(0,0,0)) temp_ob = bpy.context.object #bpy.data.objects.get("Plane") # Add a particle system. bpy.ops.object.particle_system_add() psys = temp_ob.particle_systems[-1] pset = psys.settings
But inside an operator, bpy.context.object is not the object that primitive_plane_add creates. My alternate solution is to fetch by the default name of ‘Plane’. This is rather shaky ground, however, because if I already have an object named ‘Plane’ I will get an object named ‘Plane.000’ instead and thus end up in the same boat of an object that is wrong or None for further processing.
What would be incredibly useful would be if primitive_plane_add could be extended to support a passed name value upon execution. Then I could at least know what the name of the newly created object was and fetch that directly.
Now the only reason I am fussing with primitive_plane_add is because particle_system_add seems to be the only way to add a particle system to an active selected mesh.
Does anyone know of a way to add a particle system to a mesh without using bpy.ops.particle_system_add?
What would be incredibly useful would be if particle_system_add could be extended to support a passed name value upon execution.
Here is another approach, just adding a particle system modifier.
my_ps = ob.modifiers.new("myPS",'PARTICLE_SYSTEM')
Now that I have a particle system in a variable I still need a way to add a particle system slot. This is the missing ingredient…