This question is similar to this one answered by christopheS.
So in the same principle, I just add some more information.
- An object has animation data
- This data contains curves
- A curve is defined by an 'action type' (which is defined in 'data_path') and an 'array index'
- Action type and array index will give about what the curve is. For instance an action type equal to 'location' with an array index of 1 is a curve about the Y location of the object
- The curve contains keyframe points. Each as a 'co'(ordinate) vector where co[ 0 ] is the frame and co[ 1 ] the value
Additionally you can ask the curve value using 'value = curve.evaluate( frame )'.
The code here is commented, so please tell if it is enough explanation or not.
print( '---------' )
# Action types, in order to filter the wanted curves if needed
actionTypes = ('location','rotation_euler','rotation_quaternion','scale')
# Get the object from which we want the animation data
obj = bpy.data.objects['Cube']
# If it has some animation
# Iterates over the wanted curves
# The data_path gives the action's type
for curve in [c for c in obj.animation_data.action.fcurves if c.data_path.endswith( actionTypes )]:
# The array_index give the corresponding X, Y or Z index of the curve
print( curve.data_path, curve.array_index )
for key in curve.keyframe_points:
# The curve's points has a 'co' vector giving the frame and the value
print( 'frame: ', key.co, ' value: ', key.co )