Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for help on how to export armatures and their animations in a custom export script.

I wish to have an animation format similar to BVH, i.e. a bunch of [Xposition Yposition Zposition] Xrotation Yrotation Zrotation for each bone for each keyframe.

Given the model (which exports fine using the bvh exporter), how does one get the keyframe data? A long time searching the object tree of bpy has left me somewhat baffled.

share|improve this question
Welcome to the site :) Tutorial requests are considered off topic here. If you are looking for a tutorial, then youtube or Blender Artists would be a better place to look. If you have a specific question like "How to access keyframe data with python", then this is the place. – gandalf3 Apr 7 '14 at 20:26
Noted. Any help would be appreciated (not necessarily full tutorials). My question is basically what you stated "How to access keyframe data with python", as I can do the rest. – rspencer Apr 7 '14 at 20:29
up vote 7 down vote accepted

A common way to get the animation data is to loop over the scene's frame range and read the matrices for every single frame. This is okay most of the time, and way easier to do than reading the F-Curve data directly (which won't include F-Curve modifiers and Drivers AFAIK).

Assume the Armature object is currently active:

import bpy

sce = bpy.context.scene
ob = bpy.context.object

for f in range(sce.frame_start, sce.frame_end+1):
    print("Frame %i" % f)

    for pbone in ob.pose.bones:
        print(, pbone.matrix) # bone in object space


You may use the utility function convert_space to avoid fancy matrix math.

share|improve this answer
Precisely what I was after. Thanks. – rspencer Apr 8 '14 at 7:09

To actually get the keyframe data (and not the bones' transform matrix as in CodemanX answer), you need to get the desired action, its fcurves, and finally all the keypoints.

The fcurves are named with bone.location .quaternion and .scale for all channels (x,y,z) or (w,x,y,z) and are further distinguished via their index.

action =["action_id"]
for fcu in action.fcurves:
    print(fcu.data_path + " channel " + fcu.array_index)
    for keyframe in keyframe_points
        print( #coordinates x,y

Check the API documentation on the Keyframes structure to see what you can do with it:

share|improve this answer
I think this answer is better. It actually answers the question in the title. However, could you clarify: given an object["Cube"], how do I get the action(s) of that object? – Ludwik Jul 16 '15 at 15:33
Thanks for the code, brita_! There are two syntactic errors, maybe you would consider editing them? A missing str() and a missing colon: for fcu in action.fcurves: print(fcu.data_path + " channel " + str(fcu.array_index)) for keyframe in fcu.keyframe_points: print( – Ellis Whitehead Aug 1 '15 at 6:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.