Skip to main content
[lines 18 and 34]: should be '\n{Mw}' instead of '\n{mw}' (because declared variable named with capital M)
Source Link

This code is to be run in blender 2.9 It explain how to get or convert local coordinates of a vertex to global coordinates.

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mwMw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mwMw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```
 

This code is to be run in blender 2.9 It explain how to get or convert local coordinates of a vertex to global coordinates.

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```

This code is to be run in blender 2.9 It explain how to get or convert local coordinates of a vertex to global coordinates.

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{Mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{Mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

 

Add user provided info posted as a different answer
Source Link

This code is to be run in blender 2.9 It explain how to get or convert local coordinates of a vertex to global coordinates.

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```
#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```

This code is to be run in blender 2.9 It explain how to get or convert local coordinates of a vertex to global coordinates.

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```
Notice added Needs detailed answers by Duarte Farrajota Ramos
Add proper formatting
Source Link

#############################################################

imports :

import bpy from mathutils import Vector

#############################################################

Add a Cube and Get the initial local coordinates of vertex id 0,

Get the initial Cube matrix_world,

Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add() Cube = bpy.context.object Mw = Cube.matrix_world Vert0_Lco = Cube.data.vertices[0].co Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1) print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################

Make a translation vector :

Translate the cube,

Get the final Cube matrix_world,

Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform) print (f"Cube final Matrix world :\n{mw}") # should change to : ''' Matrix(((1, 0, 0, 1 ) (0, 1, 0, 3 ) (0, 0, 1, 5 ) (0, 0, 0, 1 ))) ''' print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```

#############################################################

imports :

import bpy from mathutils import Vector

#############################################################

Add a Cube and Get the initial local coordinates of vertex id 0,

Get the initial Cube matrix_world,

Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add() Cube = bpy.context.object Mw = Cube.matrix_world Vert0_Lco = Cube.data.vertices[0].co Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1) print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################

Make a translation vector :

Translate the cube,

Get the final Cube matrix_world,

Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform) print (f"Cube final Matrix world :\n{mw}") # should change to : ''' Matrix(((1, 0, 0, 1 ) (0, 1, 0, 3 ) (0, 0, 1, 5 ) (0, 0, 0, 1 ))) ''' print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

#############################################################
# imports :
import bpy
from mathutils import Vector

#############################################################
# Add a Cube and Get the initial local coordinates of vertex id 0,
# Get the initial Cube matrix_world,
# Calculate the initial vertex id 0 Global Coordinates :

bpy.ops.mesh.primitive_cube_add()
Cube  = bpy.context.object
Mw = Cube.matrix_world
Vert0_Lco = Cube.data.vertices[0].co
Vert0_Gco = Mw @ Vert0_Lco

print (f"Vert 0 initial Local coordinates :\n{Vert0_Lco}") # should be (-1, -1, -1)
print (f"Cube initial Matrix world :\n{mw}") # should be the identity Matrix
print (f"Vert 0 initial Global coordinates :\n{Vert0_Gco}") # should be (-1, -1, -1) also

#############################################################
# Make a translation vector :
# Translate the cube,
# Get the final Cube matrix_world,
# Calculate the final vertex id 0 Global Coordinates :

Trans_Vector = Vector((1,3,5))

'''Now If you want the Cube matrix_world to be updated after the translation transform dont use<<< Cube.location = Trans_Vector >>>, instead use :'''

Mw.translation += Trans_Vector

print (f"Vert 0 final Local coordinates :\n{Vert0_Lco}")#Should be the same ( (-1, -1, -1) dont change after transform)
print (f"Cube final Matrix world :\n{mw}") # should change to :
'''
Matrix(((1, 0, 0, 1 )
        (0, 1, 0, 3 )
        (0, 0, 1, 5 )
        (0, 0, 0, 1 )))
'''
print (f"Vert 0 final Global coordinates :\n{Vert0_Gco}") # should change to (0, 2, 4)

```
Source Link
Loading