Skip to content

Instantly share code, notes, and snippets.

@TheBlizWiz
Last active July 14, 2021 15:54
Show Gist options
  • Save TheBlizWiz/f4ece3f1b038df703788c092439fc2bf to your computer and use it in GitHub Desktop.
Save TheBlizWiz/f4ece3f1b038df703788c092439fc2bf to your computer and use it in GitHub Desktop.
Blender script to take a list of poses in a pose library and turn them into keyframes
import bpy
# Leave this value at 1
start_f_pose_number = 1
# Change this value to the F number of the last pose in your
# pose library action
end_f_pose_number = 106
# *** IMPORTANT ***
# To use this script
# 1. Enter pose mode
# 2. A --> A to select all bones
# 3. Stay in Pose Mode with all bones selected, then run script
armature = bpy.context.object
# Enter the scene name inbetween the ""
# You can see it at the very top right, to the left of RenderLayer
# By default it just says Scene so type that in the ""
scene_name = ""
# This makes it so that wherever you put your current frame marker
# in your timeline is where your animation will be inserted
original_frame = bpy.data.scenes[scene_name].frame_current
for x in range (start_f_pose_number, end_f_pose_number):
y = x - 1
bpy.types.ActionPoseMarkers.active_index = y
bpy.data.scenes[scene_name].frame_set(x + original_frame)
bpy.ops.poseLib.apply_pose(pose_index = y)
for bone in armature.pose.bones:
bone.keyframe_insert(data_path = "location")
bone.keyframe_insert(data_path = "scale")
# *** IMPORTANT ***
# Remove the hashtag symbol in front of the bone.keyframe_insert()
# line that cooresponds to the type of rotation you're using for each bone
# and replace with a space
# Then add a hashtag in front of the one that was previously commented out in gray text
# I'm assuming that you're only using one type of rotation for all bones in your armature
# since the Valve Biped system uses quaternions
# If your custom rig uses a combination of any of these... you're on your own. This script
# won't work.
bone.keyframe_insert(data_path = "rotation_quaternion")
# bone.keyframe_insert(data_path = "rotation_euler")
# bone.keyframe_insert(data_path = "rotation_axis_angle")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment