2
$\begingroup$

I'm having a lot of difficulty trying to change the start and end frame of a rigid body physics simulation with python. Changing the settings in the UI shows the following in info view:

bpy.context.scene.frame_end = 850

However, running this will change the end frame of the timeline, which is not what I want. I saw the following post which solves this for cloth simulation, however this doesn't work, because the rigid body physics are not employed as a "Modifier". (Change the start frame and end frame of a bake in Blender using script)

Perhaps I have to change the context and then running the above code? I would appreciate any help implementing this, or any other way to achieve this effect.

$\endgroup$
0

1 Answer 1

4
$\begingroup$

Just figured this out, hopefully this helps someone else. If you access the point cache within the rigid body world (simply make at least one object in your scene a rigid body, otherwise no rigid body world will be created and the script will throw an error), this has a frame start and frame end which you can change with, for example:

import bpy

# Get the current scene
scene = bpy.context.scene

# Set Rigid Body World Cache Simulation Start and End Frames
scene.rigidbody_world.point_cache.frame_start = 1
scene.rigidbody_world.point_cache.frame_end = 1000

You can also set the rigid body world cache to match your scene timeline rendering / playback frame range like this:

import bpy

# Get the current scene
scene = bpy.context.scene

# Match the rigid body world's cache frames to scene start and end
scene.rigidbody_world.point_cache.frame_start = scene.frame_start
scene.rigidbody_world.point_cache.frame_end = scene.frame_end
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .