11
$\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$
1

1 Answer 1

16
$\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$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .