keyframe_insert(data_path, index=-1, frame=bpy.context.scene.frame_current, group="")Insert a keyframe on the property given, adding fcurves and animation data when necessary.
[TABLE=“class: docutils field-list”]
[TH=“class: field-name field”]Parameters:[/TH]
data_path (string) – path to the property to key, analogous to the fcurve’s data path.
index (int) – array index of the property to key. Defaults to -1 which will key all indices or a single channel if the property is not an array.
frame (float) – The frame on which the keyframe is inserted, defaulting to the current frame.
group (str) – The name of the group the F-Curve should be added to if it doesn’t exist yet.
[TR=“class: field”]
[TH=“class: field-name”]Returns:[/TH]
Success of keyframe insertion.
[/TR]
[TR=“class: field”]
[TH=“class: field-name”]Return type:[/TH]
boolean
[/TR]
[/TABLE]
This is the most simple example of inserting a keyframe from python
Note that when keying data paths which contain nested properties this must be done from the ID subclass, in this case the Armature rather then the bone.
import bpy
from bpy.props import PointerProperty
define a nested property
class MyPropGroup(bpy.types.PropertyGroup):
nested = bpy.props.FloatProperty(name=“Nested”, default=0.0)
keyframe_insert(data_path, index=-1, frame=bpy.context.scene.frame_current, group="")Insert a keyframe on the property given, adding fcurves and animation data when necessary.
[TABLE=“class: docutils field-list”]
[TH=“class: field-name field”]Parameters:[/TH]
data_path (string) – path to the property to key, analogous to the fcurve’s data path.
index (int) – array index of the property to key. Defaults to -1 which will key all indices or a single channel if the property is not an array.
frame (float) – The frame on which the keyframe is inserted, defaulting to the current frame.
group (str) – The name of the group the F-Curve should be added to if it doesn’t exist yet.
[TR=“class: field”]
[TH=“class: field-name”]Returns:[/TH]
Success of keyframe insertion.
[/TR]
[TR=“class: field”]
[TH=“class: field-name”]Return type:[/TH]
boolean
[/TR]
[/TABLE]
This is the most simple example of inserting a keyframe from python
Note that when keying data paths which contain nested properties this must be done from the ID subclass, in this case the Armature rather then the bone.
import bpy
from bpy.props import PointerProperty
define a nested property
class MyPropGroup(bpy.types.PropertyGroup):
nested = bpy.props.FloatProperty(name=“Nested”, default=0.0)
I’m not an expert on this (as my questions show!), but in my experience there are at least two ways to do it. One is to write a script that creates keyframes using the keyframe_insert() function. You would run that script first to create the F-curves, and then the animation will play back (and render) the normal way.
Another way is to create a frame change handler – a script that will be triggered every time the frame changes. In that method, no keyframes are required – the data are changed on the fly by the script. I’m sure others can tell you more.