7
$\begingroup$

I have found out that while it is possible to select vertices by setting select to True, it is not possible to deselect vertices by setting select to False if the vertices are already selected.
Sounds silly but it is not.

To demonstrate this, open a new file with the default cube, switch to Edit mode (all vertices should be selected by default).
Then run this script:

import bpy

bpy.ops.object.mode_set(mode="OBJECT")

bpy.data.meshes['Cube'].vertices[0].select = False

bpy.ops.object.mode_set(mode="EDIT")

The vertex 0 should be deselected, right? Well, it is not.

Now, deselect the top 4 vertices on the Cube and run this:

import bpy

bpy.ops.object.mode_set(mode="OBJECT")

bpy.data.meshes['Cube'].vertices[0].select = False
bpy.data.meshes['Cube'].vertices[5].select = True

bpy.ops.object.mode_set(mode="EDIT")

The vertex 5 will be a new selected one, as it should, but vertex 0 will still be selected but it should not be.

More info: if the select property's value is checked while still in Object mode, it will be False. However, switching to Edit mode makes it back to True.

Why is deselecting vertices not working? Am I missing something?

$\endgroup$
1
  • $\begingroup$ I think Blender might get confused as to which is the active obj, because selecting a vertex makes it active, and makes certain that the active stays selected, maybe you have to go back and make the original object the active again, maybe even accidentally selecting something else, you would have to go reselect the obj you want or maybe a camera or light, then deselect the vertex on the now inactive object. $\endgroup$ Apr 15, 2020 at 22:37

2 Answers 2

8
$\begingroup$

Actually, yes, you are missing something ;)

The fact is, when you select all vertices of an edge or face, you also select said edge or face (same when you select all edges of a face). In other words, selection of verts, edges and faces are linked together, so if you want to deselect vertices you must first deselect all faces and edges they belong to.

Note that selection operator(s) in editmode take care of that, using current select mode as reference (such that in vertices select mode, deselecting a vertex automatically propagates to relevant edges and faces).

$\endgroup$
4
  • $\begingroup$ Thanks, but this happens also when only a single vertex is selected - just deselect all except vertex 0 and run my example code and you will still see the same effect. Selecting single vertex does not select any faces. Is there more to it after all? $\endgroup$
    – spacer
    May 16, 2016 at 10:42
  • 1
    $\begingroup$ Cannot confirm that here… Selected a single vert, switched back to Object mode, unselected that vert in py, switched back to Edit mode, vert was no more selected… $\endgroup$
    – mont29
    May 16, 2016 at 15:31
  • 1
    $\begingroup$ I just started the test from scratch and the single vertex deselect now works. Now even the test file works. I'm buffled. How was I able to reproduce it without problems for the last 5 days!? Maybe it is some "memory effect" when several complex files are loaded and reloaded. I'll see if it appears again. Now I'm accepting the answer as it is essentially right. Thanks! $\endgroup$
    – spacer
    May 16, 2016 at 16:08
  • $\begingroup$ Is there a way to deselect all connected faces and edges etc when deselecting a vertex? I find it disappointing that there hasn't been offered an actual solution other than deselect everything and start the selection over. $\endgroup$ Oct 7, 2019 at 6:56
7
$\begingroup$

I found this question because I'm facing the same problem, looks like when vertices are already selected, before running script, for some weird reason, you cannot deselect them in context, you have to go to Edit mode, and Deselect from there, then toggle back to Object mode if working in context:

import bpy

bpy.ops.object.mode_set(mode="EDIT") #Activating Edit mode
bpy.ops.mesh.select_all(action = 'DESELECT') #Deselecting all
bpy.ops.object.mode_set(mode="OBJECT") #Going back to Object mode
$\endgroup$
1
  • 2
    $\begingroup$ Very useful. Exactly what I'm looking fo. Hat off! $\endgroup$ Mar 20, 2017 at 4:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .