10
$\begingroup$

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?

$\endgroup$
13
$\begingroup$

Use:

import bpy

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

This gives you the location from object's matrix which changes each frame for rigid bodies

$\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.