0
$\begingroup$

I have a problem which has been solved on this site before, right here:

Duplicate particle system (not linked)

Except for the fact that I am setting up my whole scene from python, and having to manually go to every object with a particle effect, click on the users icon, and set the start and end frames by hand, is becoming very tedious, when everything else in the scene has been accomplished by script.

My situation: I have a helicopter from which I am shooting rockets. I am creating the scene by reading an xml file output from another application. I start with a blend file that has one helicopter and one rocket, and then make a duplicate of the helicopter and as many duplicates of the rocket as are called for in the xml file.

The problem: I have a particle system attached to my sample rocket. I need to set the start and end frames of each rocket's particle system according to the time it was fired and the time it hit something and exploded. When I make a duplicate of the rocket, it makes a linked copy of the same particle system, so when I set the start and end frames, all the rockets end up with the same start and end frame.

I have tried every permutation of make_single_user that I can think of, but actually it doesn't even do what I want when I call it through the interface, so I'm not sure if it affects particle systems. In any event it does nothing for me in python.

Anybody know how to do this?

$\endgroup$
0
$\begingroup$

Copy the particle system settings

Here is a simple test script on what I believe you want to achieve. Select object with at least one particle system. Copies the context object, copies the settings of particle system 0, changes the start frame on copy to 22 and sets this to particle system 0 on copy.

import bpy

context = bpy.context
scene = context.scene
ob = context.object
# copy object 
obcopy = ob.copy()
# copy particle settings
ps = ob.particle_systems[0].settings.copy()
ps.frame_start = 22
# new settings on copy
obcopy.particle_systems[0].settings = ps
# link to scene
scene.objects.link(obcopy)
$\endgroup$
  • $\begingroup$ Thank you! That fixed my particles problem. However switching from duplicate_move() to copy() has created another problem for me - is there a way to tell copy() to copy the entire hierarchy of children of an object? $\endgroup$ – Chris Calef Mar 24 '18 at 2:11
0
$\begingroup$

Expanding on @batFINGER answer. If the second object (obcopy) does not have a modifier, then you would need to create a modifier before duplicating the particle settings from the original object (ob):

# Duplicate particle settings
ps = ob.particle_systems[0].settings.copy()
# Create new modifier
obcopy.modifiers.new('NewModifierName', 'PARTICLE_SYSTEM')
obcopy.particle_systems['NewModifierName'].settings = ps
# Update the automatically-generated particle settings name if desired
obcopy.particle_systems['NewModifierName'].settings.name = 'NewParticleSettingsName'
$\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.