How do you set hair dynamics and particle cache with Python?

Blender reads Python is doing this when these values are changed via the user interface:

Stiffness: bpy.context.object.pin_stiffness = 0.7
Bending: bpy.context.object.bending_stiffness = 5
Mass: bpy.context.object.mass = 0.1

However, these lines can’t be entered into the console to change these values. Tried substituting the (context.object) for the particle system, active object via context or data, no go. Same goes for when I try to change the end frame of the cache, it reads:

bpy.context.object.frame_end = 200

But this doesn’t work via the console or running from the text editor. Anyone know what the ish is?

If you hover your mouse over the parameter you want to change you can view the data path. Type that data path into your script for direct access to the parameter. Some parameters may be read-only so you may not be able to assign to them.


bpy.data.particles["ParticleSettings"].frame_end = 10

Thanks for your quick response. This doesn’t work for me though. It executes from the console without any errors, it just doesn’t actually change the value. Likewise if I use bpy.data.particles[“ParticleSettings”] as a preface to changing the hair dynamic settings, that produces an error (‘ParticleSettings’ object has no attribute ‘internal_friction’) the only setting under hair dynamics that doesn’t cause an error when run from the Console is Mass (but when you do there is the same problem as above, it doesn’t actually update the value). Note that ParticleSettings is indeed the correct name and not a duplicate or something.

When you hover your mouse over these values it reads ClothSettings.mass or whatever, should it be saying ClothSettings for hair dynamics? Also, I don’t understand how these capital letter values next to Python: in the tooltips relate to a value I can change. Most of the time there will be relative info under that but not always.

should it be saying ClothSettings for hair dynamics

Yes, it should. If you read the API docs you will see that there is a cloth portion to the particle system. You just have to keep digging down into the data structure till you reach what are after. The tool tips help but some values are clipped in the tool tip display when the datapath gets too long.

Assumes there is a particle system added to the default cube.


import bpy

ob = bpy.data.objects.get("Cube")
if ob != None:
    if len(ob.particle_systems) > 0:
        if ob.particle_systems[0].cloth != None:
            stiffness= ob.particle_systems[0].cloth.settings.pin_stiffness
            ob.particle_systems[0].cloth.settings.pin_stiffness = stiffness + 3.11
            print("assigned stiffness")
            # NOTE: You have to move your mouse over the UI field to view the updated value change.
        else:
            print("No cloth.")
    else:
        print("No particle systems.")
else:
    print("No object.")

Thanks! This works for the hair dynamics settings, but still not able to change the “frame_end” cache located under the “Cache” option. Python calls it PointCache.frame_end

The original code you provided in the first response, did that work on your machine? Or is it just mine that’s not working? Thanks again.

The original code you provided in the first response, did that work on your machine?

It works if you add a particle system to the default cube in the default scene. Obviously if you don’t have a particle system named “ParticleSystem” inside of bpy.data is will not work. Change the name as needed.

I don’t think you have to worry about the frame_end for the point cache anymore. It is not even available inside the UI for Blender 2.70. You mention that you could not change it. This means you were able to access/read the value correct? Perhaps you could not change it because the cache was baked?