4
$\begingroup$

I'm making simulation in blender for rigid body. I need object location in the current frame. I use following command

bpy.context.scene.frame_set(250)
bpy.data.objects['Object'].location

but this command returns the location corresponding to the initial frame. Neither changes object location in Location panel during simulation. I know I can bake rigid body transformations to keyframes but I need another way to get location of object because baking takes long time for multiple objects. Is there any other command which can print object location after transformation without baking?

$\endgroup$

1 Answer 1

7
$\begingroup$

Yes, Location/Rotation/etc. returns the values visible in relevant fields of the object transform in the UI, kind of 'initial' transformation. To get final one, you can use:

bpy.context.scene.frame_set(250)
bpy.data.objects['Object'].matrix_world.translation

Note that:

  1. This gives you absolute position of the object (world space), if you want its relative position (to parent e.g., local space), you'll have to use matrix_local.
  2. You should bake physics simulation before using frame_set().
$\endgroup$
1
  • $\begingroup$ Thanks so much. I actually used this to export a model after doing physics simulations for. $\endgroup$
    – Amir
    Commented Sep 1, 2016 at 23:06

You must log in to answer this question.

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