# How to get keyframes and related information?

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?

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 :
print('frame:',key.co[0],'value:',key.co[1])


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

• I think it would be useful to add some explanation alongside the code to explain the methodology. Feb 26 '17 at 14:18
• @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? Feb 26 '17 at 14:23
• key.co return a tupple with the first element is the frame and the second is the value Feb 26 '17 at 14:41
• 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... Feb 26 '17 at 15:00
• Feb 26 '17 at 15:00