Track Object's Location Frame by Frame?

This seems like it should be very easy, so I’m sure that I’m missing something here. I simply need to know the location of an object during it’s animation. For some reason when I try to access this info it simply acts like the object is not moving or changing at all.

This is how I’ve tried to do it, is there a better way?

import bpy


Objct=bpy.context.object.name
sf=bpy.context.scene.frame_current
ef=60
for i in range(sf, ef):
    
    bpy.context.scene.frame_current=i
    print ("Current Frame:", i)
    print ("Object X:", bpy.data.objects[Objct].location.x)
    print ("Object Y:", bpy.context.object.location[1])
    
bpy.context.scene.frame_current=sf

Thanks for any available feedback.

try using frame_set(i) instead…


import bpy
obj = bpy.context.object
sf = bpy.context.scene.frame_current
ef = 60

for i in range( sf, ef ):    
    bpy.context.scene.frame_set( i )
    print ( "Current Frame:", i )
    print ( "Object X:", obj.location[0] )
    print ( "Object Y:", obj.location[1] )
    
bpy.context.scene.frame_set( sf )

Worked like a charm! I knew I was just a little off. Thanks a lot.

glad to help