# Getting the location of rigid body object at current keyframe

I would like to print out the location of an object with this script:

import bpy

obj = bpy.data.objects["Cube"]
print(obj.location)


It prints it out correctly, but when I animate this object (it's a rigid body) and then at a particular keyframe I run this script again, it just prints out the same location.

I tried to set the frame with:

bpy.context.scene.frame_set(fr)


Like it is mentioned in these two questions:

But the location just stays the same. How can I get the correct location of the cube?

import bpy