In Blender, we can select and deselect mesh vertices through the “select” property for each vertex.
However, to deselect a vertex, it is not enough to set it’s “select” property to “False”
To deselect a vertex, first, we need to deselect polygons to which this vertex belongs and edges on which this vertex lies. And only after that, we can deselect the vertex itself.
For example, to deselect all mesh vertices, we need to execute the following code:
for polygon in bpy.context.active_object.data.polygons:
polygon.select = False
for edge in bpy.context.active_object.data.edges:
edge.select = False
for vertex in bpy.context.active_object.data.vertices:
vertex.select = False
To work with the selection we must switch to the “OBJECT” mode, otherwise, selection changes will not be applied to the mesh.