Insert keyframe for rigid body properties for object python script blender I have a bunch of objects falling onto a plane, and want to have them fall at different frames (i.e, Object1 falls at frame 1, Object2 falls at frame 100, etc)

Could anyone help me with trying to set a keyframe for the activation using the python script console?

I can do this by manually setting keyframes for the "Dynamic" checkbox in the Rigid Body dropdown, however I would like to automate this.

here is my code so far:

bpy.ops.import_mesh.stl(filepath="C://Users/deden/Desktop/x0y0z0h1.stl")
bpy.ops.rigidbody.object_add(type="ACTIVE")

I would imagine the keyframe command would look something like this:

bpy.context.active_object.keyframe_insert(data_path="rigidbody",frame=100)


But I cannot get it to work and haven't found any specific examples.

Alternatively, if anyone could show me how to add these different objects at different frames that would achieve the same result. For this approach I've tried code like:

bpy.context.scene.frame_set(frame=100)
bpy.ops.import_mesh.stl(filepath="C://Users/deden/Desktop/x0y0z0h1.stl")
bpy.ops.rigidbody.object_add(type="ACTIVE")


but when I play the animation all the objects are in place at the beginning of the animation as opposed to the frame I set it to before importing?

Please help!! End goal = objects falling at different times, whether its setting the rigid body properties with keyframes or importing the objects at different frames with rigid body activated

Thanks!
You have to use the correct datapath.

bpy.context.active_object.keyframe_insert(data_path="rigid_body.kinematic",frame=100)



Select the object, make it active.
Enable the animated (rigidbody.kinematic) property and keyframe it.
Disable the animated property on the frame you want to have the object start simulating and keyframe it.


This script assumes there is an object called Cube in the active scene.



import bpy

obj = bpy.data.objects['Cube']

start_frame = 100

# make the object the active object
bpy.context.scene.objects.active = obj
obj.select = True
bpy.ops.rigidbody.object_add()


obj.rigid_body.kinematic = True
obj.keyframe_insert(data_path="rigid_body.kinematic",frame=start_frame)
obj.rigid_body.kinematic = False
obj.keyframe_insert(data_path="rigid_body.kinematic",frame=start_frame+1)


Look at the python tooltips.