Accessing animation data in Python
Let’s switch to the Scripting Workspace area to familiarize ourselves with the animation system API.
Adding keyframes in Python
The Python class of every animatable object provides a method that we can use to insert keyframes, named keyframe_insert
. It is very similar to the Insert Keyframe menu and requires a data_path
string for specifying which property to animate. Optional parameters such as index
and frame
allow us to specify one of the channels of an aggregate property or a frame different from the current one:
keyframe_insert(data_path, index=- 1, frame=bpy.context.scene.frame_current, […] Returns Success of keyframe insertion.
The following lines set a keyframe for the active object...