0
$\begingroup$

I have been using this code to add a new particle system and create a name for it... I need help to choose the particle type "HAIR" and set other parameters.. This script does not work because the [part.001] keeps changing and going up. It will only work once when creating the first name. I will need one particle system, so I can apply the code on other objects as well. It is a bit confusing. The MBall is used as a particle to cover the entire surface of an object.

import bpy

obj = bpy.context.active_object
obj.modifiers.new("part", type='PARTICLE_SYSTEM')

bpy.data.particles["part"].type = 'HAIR'

bpy.data.particles["part"].count = 15000
bpy.data.particles["part"].use_advanced_hair = True
bpy.data.particles["part"].render_type = 'OBJECT'
bpy.data.particles["part"].instance_object = bpy.data.objects["Mball"]
bpy.data.particles["part"].particle_size = 0.15
bpy.data.particles["part"].emit_from = 'FACE'
bpy.data.particles["part"].distribution = 'RAND'
'

enter image description here

$\endgroup$
1
$\begingroup$

Python console code.

Add a particle system to the context object, Note the reference returned ps if the system names this system "part.001" it will be ps.name

>>> ob = C.object
>>> ps = ob.modifiers.new("part", 'PARTICLE_SYSTEM')
>>> ps.name
'part'

another

>>> ps = ob.modifiers.new("part", 'PARTICLE_SYSTEM')
>>> ps.name
'part.001'

The newly created particle system in the objects particle system collection

>>> psys = ob.particle_systems[ps.name]

psys.settings is a pointer to the particle settings stored in bpy.data.particles referred to by this particle system. Notice it has the name "part.001" but we haven't used the name to find it at all, only a reference and pointer

>>> psys.settings
bpy.data.particles['part.001']

Use this pointer to set some properties (as in question code)

>>> psys.settings.count = 10000
>>> psys.settings.type = 'HAIR'

Can use this to set to a predefined set of settings, in this example a previously defined group of settings named "Wooble"

>>> psys.settings = D.particles['Wooble']
>>> 
$\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.