As with normal mesh manipulation via the Blender Python API, when using the BMesh object to deselect vertices, it is not enough to simply change the value of their “select” property to the opposite. To deselect the vertices of the BMesh object, the “select” value must also be changed for the edges and polygons adjacent to them.
Manipulations with the BMesh object are carried out in object mode. Switch to it.
1 |
bpy.ops.object.mode_set(mode='OBJECT') |
Create a BMesh object, using the data of the current active object for it.
1 2 |
bm = bmesh.new() bm.from_mesh(bpy.context.object.data) |
If we try to deselect just the vertices:
1 2 |
for vertex in bm.verts: vertex.select = False |
We won’t see any result.
To remove the selection, remove it sequentially for faces, edges and vertices.
1 2 3 4 5 6 |
for face in bm.faces: face.select = False for edge in bm.edges: edge.select = False for vertex in bm.verts: vertex.select = False |
Flush the changed data back into the active object
1 |
bm.to_mesh(bpy.context.object.data) |
And switch back to the edit mode
1 |
bpy.ops.object.mode_set(mode='EDIT') |
Now we can see that all the selection from the vertices of the mesh is completely removed.