# Modifying vertex coordinates not working

I’m trying to write coordinates into a vertex but somehow it doesn’t seem to take input

Every time this runs it prints some “2”s in the console as if it worked, but the next run they’re back to being 1 and -1 again.

import bpy
import bmesh

obj=bpy.context.edit_object
m=obj.data
bm=bmesh.from_edit_mesh(m)

print("---")

for i in range(0,8):

v=bm.verts[i]

[email protected]
print(co.x)
co.x=2
print(co.x)

bmesh.update_edit_mesh(m)


Well, the problem is here:

[email protected]


So here you have used an operator @. Like adding + or multiplying * it gets 2 entities, makes an operation with them and results a new entity. The @ operator applies a transformation matrix on vector v.co and the result of this operation is saved in co property. So instead of linking the data it creates new data, so that assigning something to co doesn't make sense, because it holds a modified copy, not the link.

I suppose you can solve this like this:

import bpy
import bmesh
# import new module
import copy

obj=bpy.context.edit_object
m=obj.data
bm=bmesh.from_edit_mesh(m)

print("---")

for i in range(0,8):

v=bm.verts[i]

[email protected]
print(co.x)
co.x=2
print(co.x)

# get a copy of transform matrix to be able to invert it:
inverted = copy.copy(obj.matrix_world)
inverted.invert()

# now write property to the cube
v.co = inverted @ co

bmesh.update_edit_mesh(m)


I have used inverted matrix to write coordinates back.

• Thank you so much! I am very new to scripting so I just scavenged some code off of the web and put it together without really understanding much of it. I had no idea what the @ was. Could you point me to some systematic learning resources for Blender scripting? When I try to find resources the books are usually outdated and the online tutorials do not fully cover the fundamentals Commented Jun 14, 2022 at 23:38
• The course on blender cloud should be helpful, and it gets updated then something is changed in API studio.blender.org/training/scripting-for-artists Commented Jun 14, 2022 at 23:40
• Fantastic! I appreciated it Commented Jun 14, 2022 at 23:43