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$
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$
  • $\begingroup$ Thanks so much. I actually used this to export a model after doing physics simulations for. $\endgroup$ – Amir Sep 1 '16 at 23:06

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.