1
$\begingroup$

I created a Bezier curve, my camera is following that curve, tracking an object and thus rendering it from different angles. While running this animation, I also want to print/record the camera pose using Python. I can start the animation in Python using:

import bpy
bpy.ops.screen.animation_play()

But how can I get cam.location for each animation frame?

$\endgroup$
1
$\begingroup$
import bpy

def handler(scene):
    print("Frame Change", scene.frame_current)
    print("Camera location", scene.camera.location)
    
bpy.app.handlers.frame_change_pre.append(handler)

bpy.ops.screen.animation_play()

Will print the frame number and camera location at each frame.

This works because you can write a handler that is invoked each time the frame number changes. In this case, the handler runs before the frame is displayed or rendered. See this page of the manual for details.

This will print to the system console, and it will do so every time the frame is changed, including when you manually scrub the timeline cursor.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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