Setting rigid body cache start frame to active frame.

id like to have the rigid body cache start frame to be set to any active frame at the press of a button and have another button that “resets” it back by setting it back to 1. is that possible? any python lords out there that know how to achieve this?

Hi Albertofx,

Quick hack from simple object operator. Prepends button to scene cache panel, and physics props panel.


import bpy
from bpy.props import IntProperty


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "scene.rigidbody_set_frame_start"
    bl_label = "Rigid Body Frame Start"
    frame_start = IntProperty(default=1)

    @classmethod
    def poll(cls, context):
        # add rigidbody test
        return True

    def execute(self, context):
        scene = context.scene
        scene.rigidbody_world.point_cache.frame_start = self.frame_start
        return {'FINISHED'}

def add_buttons(self, context):
    layout = self.layout
    row = layout.row()
    scene = context.scene

    fs = 1
    if scene.rigidbody_world.point_cache.frame_start == 1:
        fs = scene.frame_current
        
    op = row.operator("scene.rigidbody_set_frame_start", text="Start Frame %d" % fs)
    op.frame_start = fs   

def register():
    #prepended to rigid body cache
    bpy.types.SCENE_PT_rigid_body_cache.prepend(add_buttons)
    #prepended to physics
    bpy.types.PHYSICS_PT_add.prepend(add_buttons)
    bpy.utils.register_class(SimpleOperator)


def unregister():
    #prepended to rigid body cache
    bpy.types.SCENE_PT_rigid_body_cache.remove(add_buttons)
    #appended to physics
    bpy.types.PHYSICS_PT_add.remove(add_buttons)
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

Thank you so much!
how can the button be added to the toolbar instead? best if its the physics tab.

In the physics 3dview toolbar.


import bpy
from bpy.props import IntProperty


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "scene.rigidbody_set_frame_start"
    bl_label = "Rigid Body Frame Start"
    frame_start = IntProperty(default=1)

    @classmethod
    def poll(cls, context):
        # add rigidbody test
        return True

    def execute(self, context):
        scene = context.scene
        scene.rigidbody_world.point_cache.frame_start = self.frame_start
        return {'FINISHED'}

def add_buttons(self, context):
    layout = self.layout
    row = layout.row()
    row.label("Start Frame")
    row = layout.row()
    scene = context.scene

    fs = 1
    if scene.rigidbody_world.point_cache.frame_start == 1:
        fs = scene.frame_current
        
    op = row.operator("scene.rigidbody_set_frame_start", text="Start Frame %d" % fs)
    op.frame_start = fs   

def register():

    bpy.types.VIEW3D_PT_tools_rigid_body.append(add_buttons)
    bpy.utils.register_class(SimpleOperator)


def unregister():

    bpy.types.VIEW3D_PT_tools_rigid_body.remove(add_buttons)
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()