# No redraw after assigning new vertex position with python

I'm trying to write a new operator which modifies my geometry in some way, but I'm struggling with vertex manipulation. I can get the selected vertices fine and also print the individual components. So, lets say I have a vertex v. I can get the position of this vertex via v.co. But when I set a new value for this vertex with my operator it does not redraw in the 3D View. I assign a new value like this:

v.co = Vector((1,2,3))


Like said above the 3D View does not update. I have to quit my operator and navigate in the 3D View to update. What do I have to do to make blender update the 3D View correctly?

If your running the script with the object in edit mode then you can use

# Note that bmesh is the module named bmesh, not an instance of a BMesh.
# me is an instance of Mesh, again, not an instance of a BMesh.
bmesh.update_edit_mesh(me)


If your running in object mode then you need something that will trigger an update, not sure if this is the best way but

bpy.context.scene.objects.active = bpy.context.scene.objects.active


triggers an update in the 3dview.

If you use a wrapped bmesh...

bm = bmesh.from_edit_mesh(me)


... use update_edit_mesh() to flush changes. Note that Blender will crash otherwise if geometry was added or removed.

If it's not a wrapped bmesh...

bm = bmesh.new()
bm.from_mesh(me)


... write the bmesh back to mesh:

bm.to_mesh(me)


To update a mesh, use:

me.update()