I created a simulation of falling apples into a box. For research purposes, I want to be able to export the XYZ Coordinates of all apples (center of mass of objects, if possible) into a dataset, only for the last frame of the simulation.

enter image description here

I'm new to blender, and have a basic knowledge in Python. Any direction will do nicely.


Bake, then use the matrix world translation

As proposed here Is there any way to export the last frame of a physics simulation from command line?

bake the sim, then in this case instead of exporting, run thru the objects in the scene and print their global translation. in lieu of Formatting and writing data to a text file

Make the origin of the physics objects the center of mass when setting up.

import bpy
context = bpy.context

scene = context.scene
rbw = scene.rigidbody_world
pc = rbw.point_cache

# match bake to animation
print(pc.frame_start, pc.frame_end)

bpy.ops.ptcache.bake({"point_cache": pc}, bake=True)


for ob in scene.objects:
    print(ob.name, ob.matrix_world.translation)

Result on default file, cube made a default rigid and dropped

Cube <Vector (0.0000, 0.0000, -460.8643)>
Lamp <Vector (1.7122, 1.0489, 8.5606)>
Camera <Vector (5.1171, -6.4642, 8.0004)>
  • $\begingroup$ Thank you! definitely enough for me to go on $\endgroup$ – Nadav Halali Jul 12 '20 at 10:29

It's easy, if you know python. Use text editor in Blender to write script, and play button (in script editor, not in timeline) to run it

enter image description here

Get selected objects from bpy.context.selected_objects. Then you can get location of object (in current frame) from its location property.

import bpy

for obj in bpy.context.selected_objects:

When you run this script, you will find in terminal something like this:

enter image description here

Each individual component: obj.location.x, obj.location.y, obj.location.z

  • $\begingroup$ Looks more simple than I imagined, thanks! $\endgroup$ – Nadav Halali Jul 12 '20 at 10:29

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.