Export location of an object of each frame to a txt file.

Hi guys.

I’m traying to save the location of an object and save it in a txt file, I can do that in one frame but I don’t how to put this and make it for each frame depending the length of the timeline. This is the code: (I am a NOOB with Python, sorry for the syntaxis)

import bpy, os

selection = bpy.context.selected_objects

resultado1 = “”

for sel in selection:
dims = sel.location
resultado1 += "%s : Locación: X=%.03fm Y=%.03fm Z=%.03fm
" % (sel.name, dims.x, dims.y, dims.z)

path = “C:/Users/Luis Voronov/Desktop/Guardar Datos”
os.makedirs(path, exist_ok=True)
file = open(“Datos.txt”, “w”)
file.write(resultado1)
file.close()

Can anyone help me?

Thanks.

hi Luis, you would need to advance frames in timeline from the script, using your code something like this:

import bpy, os
sce = bpy.context.scene
selection = bpy.context.selected_objects
resultado1 = ""

for f in range(sce.frame_start, sce.frame_end + 1):
    sce.frame_set(f)
    for sel in selection:
        dims = sel.location
        resultado1 += "%03d %s: Locación: X=%.03fm Y=%.03fm Z=%.03fm
" % (f, sel.name, dims.x, dims.y, dims.z)

file = open("C:\\Temp\\info.txt", "w")
file.write(resultado1)
file.close()

there’s a io_anim_camera.py script in blender you can check, or many others