Global Coordinates for Mesh Vertices

I’m trying to get the global coordinates of each vertex in a mesh. To test I have a mesh named “tester” composed of a single vertex. The forums have guided in writing this:

import bpy
from mathutils import *

def A():
    actOb = bpy.context.scene.objects['tester']
    wmtx =  actOb.matrix_world.inverted()
    vertList = [(vertex.co *wmtx) for vertex in actOb.data.vertices]
    
    for v in vertList:
        print (v) 
    
A()    


But the printed values are different from the values in the Transform dropdown in the view properties (see attached pic). What am I missing?


don’t invert the matrix… world matrix transforms local space to world space. object.data.mesh.vertcies[n].co gives a local space vector. So multiplying that by the inverse is not the operation you are after.

Thanks for the reply patmo141! I removed the inversion and it gives me the same thing. Any idea why the last value (Z value I assume) doesn’t match the value in the “Transform” slider?

Ok, so I was originally testing on a mesh with shapekeys. Of course that would be off… :spin:

Now when I apply the same script minus the inversion I get inverted values (?). So confused…





import bpy
from mathutils import*

def A():
* ** actOb = bpy.context.scene.objects['tester']
* ** wmtx = *actOb.matrix_world
* ** vertList = [(wmtx * vertex.co) for vertex in actOb.data.vertices if vertex.select]
** *
* * for v in vertList:
* * print (v)
** *
A()



should be

wmtx * vertex.co # not the other way around!!!

if you don’t mind altering the original mesh:

mesh.transform(wmtx)

Thank you so much zmj100 and CoDEmanX! Problem solved :ba: