Moving verts only works in object mode

Hi, why does the following script only work when in object mode.
I would have expected it only to work in edit mode, because it’s operating on individual components rather than the object as a whole.
What am I misunderstanding?

import bpy

selectedVerts = [v for v in bpy.context.active_object.data.vertices if v.select]

for vert in selectedVerts:
    new_location = vert.co
    new_location[0] = new_location[0] + 2 
    new_location[1] = new_location[1] + 2
    new_location[2] = new_location[2] + 2
    vert.co = new_location

In edit mode you need to access geometry using bmesh

2 Likes

This should do it.

import bpy, bmesh

m = bpy.context.object.data
b = bmesh.from_edit_mesh(m)
s = [v for v in b.verts if v.select]

for v in s:
    n = v.co
    n.x += 2
    n.y += 2
    n.z += 2

bmesh.update_edit_mesh(m)
2 Likes

Thanks guys,
Can I use bmesh to read the color data of selected vertices?

yes, color data is stored in loops. an example of how to do this can be found here.

1 Like