0
$\begingroup$

I'm working on a script that makes a rigid body simulation, I'm interested to get the final position and rotation of my objects but I have not idea how to do considering that I'm pretty new in the using bpy. Anyone has an idea how to code it? To be clear on the data that I wanna get i'll achieve a screenshot from blender panel. Thank you!

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

The data is utilized to establish the starting point of the object. When using constraints or rigid body physics, these values are employed to populate a transform matrix that is utilized in simulations. To obtain the transform matrix, use either the matrix_world or matrix_local (if related to a parent). The values can be accessed using translation and to_euler() methods.

obj = bpy.data.objects["Your object name"]
print(obj.matrix_world.translation)
print(obj.matrix_world.to_euler())
$\endgroup$
4
  • $\begingroup$ Thank you so much, your suggested code works but at this point the problem is that, when I run the code on Blender I get different results than I run the code from, for example, the command prompt and I don't know why. $\endgroup$ May 18, 2023 at 9:38
  • 1
    $\begingroup$ Are you sure that Rigid body sim has been run or baked? $\endgroup$
    – Crantisz
    May 18, 2023 at 11:09
  • $\begingroup$ Yes I am, I've checked on Blender and the simulation has been run. $\endgroup$ May 18, 2023 at 13:21
  • $\begingroup$ I fixed the problem, basically the solution was to run the script on Blender because when I run it on visual studio code the rigid body simulation didn't bake. $\endgroup$ May 19, 2023 at 6:27

You must log in to answer this question.

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