I'm a bit (or more...) lost about keyframes and fcurves information even if I have read this question and answers or others and tried to understand the related documentation.

What I'm trying to do is the following:

  • Looping along frames which have keyframes set on them (only these frames)
  • For each keyframe retrieve the related keyed objects (I'm interested in objects and bones only) and retrieve the keyframe information (location, rotation or scale only)

How to do that in Python?


1 Answer 1


I think it's something like that :

import bpy

for ob in bpy.context.scene.objects :
    if ob.type in ['MESH','ARMATURE'] and ob.animation_data:
        for fc in ob.animation_data.action.fcurves :
            if fc.data_path.endswith(('location','rotation_euler','rotation_quaternion','scale')):
                for key in fc.keyframe_points :

Keyframe in blender are not store in one place. It's store on action related to object. You can look throw all keyframe on your blend file in bpy.data.actions. To filter by object type you have to look throw objects in your scene and find the related action

  • 2
    $\begingroup$ I think it would be useful to add some explanation alongside the code to explain the methodology. $\endgroup$ Commented Feb 26, 2017 at 14:18
  • $\begingroup$ @RayMairlot, I agree. I get the way the code is. My problems are more about the data itself. For example, what contains key.co exactly (the doc is lean about all that). And, do these key.co contain only the keyframes visible in the timeline? $\endgroup$
    – lemon
    Commented Feb 26, 2017 at 14:23
  • $\begingroup$ key.co return a tupple with the first element is the frame and the second is the value $\endgroup$ Commented Feb 26, 2017 at 14:41
  • $\begingroup$ So key.co[1] is a weighting (because value is very broad)? I will accept your answer as it gives me a great help. But the really hard thing (to me) learning all these is about the meaning of what is accessible... $\endgroup$
    – lemon
    Commented Feb 26, 2017 at 15:00
  • 2
    $\begingroup$ Related blender.stackexchange.com/questions/27889/… $\endgroup$
    – batFINGER
    Commented Feb 26, 2017 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .