1
$\begingroup$

I want to be able to access the posed xyz location data for objects parented to an armature.

I can do this for bones:

bpy.data.objects["spine_armature"].pose.bones['Bone.007'].matrix.to_euler()

but how do I do that for the objects listed under the armature? Armature objects

So far the location I have accessed for object location doesn't seem to change when I change the pose - like it is the original un-posed location.

How would I access the posed object location data by name? (not by currently active object)


Edit: the original title still stands, but I could be looking in the wrong place for the pose location data.

When I access

bpy.data.objects["spine_armature"].children

it does give the children of spine_armature, but the vector data doesn't seem to change after the pose has changed.

I'm looking to find the new posed location of an object. The location data for a posed object doesn't seem to change. What data changes that has the new location data?

enter image description here

enter image description here

$\endgroup$

2 Answers 2

1
$\begingroup$

Found it! I was searching for something else Python and came across the beginning of what I needed in the "How to get frame-by-frame object location in Blender 2.8+" post.

As the answer there says

the object origin "stays" at its original position

Thanks to:

I have put together some code that gives me the position of an object relative to it's resting pose position. If I wanted the absolute position, I could add the two points.

In the code Vert_8_3 is the object in question, a single vert object

context = bpy.context
vertebre_obj = context.scene.objects['Vert_8_3']
depsgraph = context.evaluated_depsgraph_get()
bm = bmesh.new()
bm.from_object(vertebre_obj, depsgraph)

if hasattr(bm.verts, "ensure_lookup_table"): 
    bm.verts.ensure_lookup_table()

vertebre_data = bm.verts[0].co.xyz

bm.verts[0] throws the error IndexError: BMElemSeq[index]: outdated internal index table, run ensure_lookup_table() first if the following is not added before accessing the location data:

if hasattr(bm.verts, "ensure_lookup_table"): 
    bm.verts.ensure_lookup_table()
$\endgroup$
2
  • 1
    $\begingroup$ If the order of the vertices is not important (and clearly it isn't if there's just one), you could use bm.verts[:][0] instead - to copy the list and then access it without an error. Of course use the trick with caution: the error is there to save you from heisenbugs based on semi-random vertex ordering if the lookup is not ensured. As well as if you have a lot of vertices (but still don't care about their order), you can use next(v for v in bm.verts) to get one without generating an entire list of them. $\endgroup$ Jan 22, 2022 at 17:02
  • $\begingroup$ Thanks; I actually ran into the vertex order issue when trying to sum up the distances on an object - turned on the index display and edge length - displaying weird results even though the order seems ok - but that's another unrelated issue :) $\endgroup$
    – jmhead
    Jan 23, 2022 at 8:37
0
$\begingroup$
import bpy

for oj in bpy.data.objects["spine_armature"].children:
    print(oj.location)
$\endgroup$
0

You must log in to answer this question.

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