6
$\begingroup$

I need to move vertices along axis Z GLOBAL but I don't find how to do it. I've tried this:

ob = bpy.data.objects["object1"] #the vertices belong to object1
mat = ob.matrix_world
matloc = ob.matrix_local
for i in range( 0, len(poligonos) ):
    v = mesh.getVertex(0, poligonos[i]) #poligonos is an array where I store the index of each vertex that I want to move
    glo = mat * v.XYZ
    glo.x = glo.x
    glo.y = glo.y
    glo.z = glo.z - 0.1
    aux = matloc * glo
    v.setXYZ([aux.x, aux.y, aux.z])

But this code moves my vertices to weird locations and what I need is the vertices go down in 0.1

$\endgroup$

2 Answers 2

12
$\begingroup$

Worked for me:

import bpy

obj  = bpy.data.objects['Cube']
mesh = obj.data
vert = mesh.vertices[0]
mat_world = obj.matrix_world

pos_world = mat_world * vert.co
pos_world.z += 0.1
vert.co = mat_world.inverted() * pos_world

If you're editing a lot of vertices then you might want to compose the matrix:

from mathutils import Vector, Matrix

vec = Vector((0.0, 0.0, 0.1))  
mat_edit = mat_world.inverted() * Matrix.Translate(vec) * mat_world

vert.co = mat_edit * vert.co
$\endgroup$
1
  • $\begingroup$ Does this no longer work? I get AttributeError: '_BPyOpsSubModOp' object has no attribute 'inverted' $\endgroup$ Sep 22, 2023 at 0:49
1
$\begingroup$

The answer of "pink vertex" is a great idea but finally I fixed the problem like this:

for i in range( 0, len(poligonos) ):
    v = mesh.getVertex(0, poligonos[i])
    glo = mat * v.XYZ
    glo.z += 0.1
    v.XYZ = mat.inverted() * glo
$\endgroup$

You must log in to answer this question.

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