11

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?

Amir
  • 3,074
  • 2
  • 29
  • 55
padr
  • 390
  • 2
  • 10

1 Answers1

16

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

Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218
  • se the answer to http://blender.stackexchange.com/questions/38466/after-setting-constraints-the-location-of-constrained-objects-bodies-is-not-acce for a slightly longer explanation of why this works. – rfabbri Sep 13 '15 at 18:55