I need script that can save animated camera position and rotation to file every frame. Ideally in .csv format. Camera will follow path.

Expected result:

001,0.0,-8.42116,3.4081,70.3,0,0 002,......

where: frame,location x,y,z, rotation x,y,z

I have very basic knowledge about programming, but I'll be thankful also for guides me to the right direction.

Thanks for your time :-)


From the text_editor templates > python > operator_file_export.py . Changed the write_some_data function to export matrix_world location of active object.

Just using location and rotation_euler will not give visual location when there are constraints or follow_path (et al).

def write_some_data(context, filepath, use_some_setting):
    print("running write_some_data...")
    camera = context.active_object
    mw = camera.matrix_world
    scene = context.scene
    frame = scene.frame_start

    f = open(filepath, 'w', encoding='utf-8')
    while frame <= scene.frame_end:
        x, y, z = mw.to_translation()
        rx, ry, rz = mw.to_euler('XYZ')
        f.write("%d" % frame)
        f.write(", ")
        f.write("%5.3f, %5.3f, %5.3f" % (x, y, z))
        f.write(", ")
        f.write("%5.3f, %5.3f, %5.3f" % (rx, ry, rz))
        frame += 1

    return {'FINISHED'}

Your Answer

