Skip to content

Instantly share code, notes, and snippets.

@naphthalene
Last active August 29, 2015 14:09
Show Gist options
  • Save naphthalene/9f20c7d43abef50f2b49 to your computer and use it in GitHub Desktop.
Save naphthalene/9f20c7d43abef50f2b49 to your computer and use it in GitHub Desktop.
import bpy
from math import pi
## Create a set of keyframes for Suzanne using Blender python
bpy.ops.graph.interpolation_type(type="CUBIC")
suzie = bpy.data.objects['Suzanne']
# Each keyframe is (frame, location, rotation, scale)
keyframes = [
(1, (0, 0, 1), (0, 0, 0), (1, 1, 1)),
(11, (1, 1, 1), (pi/2, pi/2, pi), (1, 1, 1)),
(21, (1, 2, 1), (pi/2, pi/2, pi), (0.5, 0.5, 0.5)),
(31, (1, 2, 1), (pi, pi, 0), (0.5, 0.5, 0.5)),
(41, (2, 2, 3), (0, 0, 0), (3, 3, 3))
]
for k in keyframes:
bpy.context.scene.frame_set(k[0])
suzie.location = k[1]
suzie.rotation_euler = k[2]
suzie.scale = k[3]
suzie.keyframe_insert(data_path="location")
suzie.keyframe_insert(data_path="rotation_euler")
suzie.keyframe_insert(data_path="scale")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment