Get the transform matrix for each frame I'm new to scripting inside blender (two days). I have a camera folowing a path (a circle).

I have written the following code to get the location and rotation for each frame and write it to a file:  

import bpy

transformMetrix=open('C:\\Users\\sunimalm\\Desktop\\transformMetrix.txt','w')


for f in range(bpy.context.scene.frame_start,bpy.context.scene.frame_end):
    for obj in bpy.context.selected_objects:
        transformMetrix.write('\n'+obj.name+'\n')
        transformMetrix.write('\n'+ str(f)+'\n')
        transformMetrix.write('Location : ' + str(obj.location.x) +' '+ str(obj.location.y) +' '+ str(obj.location.z) +'\n')
        transformMetrix.write('rotation : ' + str(obj.rotation_euler.x) +' '+str(obj.rotation_euler.y) +' '+str(obj.rotation_euler.z)+'\n')
        transformMetrix.write('scale : ' + str(int(obj.scale.x)) +' '+str(int(obj.scale.y))+' '+str(int(obj.scale.z)) +'\n')

transformMetrix.close()


When I play and run the script I only get the same rotation and location matrix for every frame.



What am I doing wrong here? 

Then I tried to put above code inside a function and append it to a handler, but I still get the same output: 

bpy.app.handlers.frame_change_post.append(function)
You have to change the frame in your for-loop via Scene.frame_set():

bpy.context.scene.frame_set(f)


By the way, I would not use obj.location, rotation_euler etc. because they do not contain the final location, rotation and so on.
For example, parent your camera to an object, then rotate the object - the camera.rotation_euler will not change.

You should use obj.matrix_world instead (if you need it separated, decompose this matrix with to_location, to_euler etc.)