Page MenuHome

vertex.select=False does not work, but vertex.select=True does work
Closed, InvalidPublic

Description

System Information
Win7 64 bits with sp1

Blender Version
Broken: official 2.76b 64 bits

Exact steps for others to reproduce the error
I want to select/deselect some vertices based on some conditions, for example

  1. for the default scene, we enter the EDIT mode and can find that all the 8 vertices of the cube are selected. Then run this script
import bpy
for obj in bpy.data.meshes:
    bpy.ops.object.mode_set(mode="OBJECT")
    for vertex in obj.vertices:
        if vertex.co.x<0:
            vertex.select=False
            print (vertex.select)
    bpy.ops.object.mode_set(mode="EDIT")
    bpy.context.scene.update()

We find that nothing changes, and all 8 vertices are still selected!

  1. now we deselect all vertices by hand( A-key in 3d window), and run this
import bpy
for obj in bpy.data.meshes:
    bpy.ops.object.mode_set(mode="OBJECT")
    for vertex in obj.vertices:
        if vertex.co.x<0:
            vertex.select=True         #Please note this is True, but above code is False
            print (vertex.select)
    bpy.ops.object.mode_set(mode="EDIT")
    bpy.context.scene.update()

we can find 4 vertices are selected now.

We can repeat case 1 and 2 many times as you wish. So I am puzzled, why does Blender operate "vertex.select=True", but omit "vertex.select=False"? For consistency, if one operation is allowed, why not allow another? Or blender should ban 2 operations by make vertex.select is a read-only atributes?

Details

Type
Bug

Event Timeline

Lee June (retsyo) added a project: BF Blender.
Lee June (retsyo) set Type to Bug.
Lee June (retsyo) created this task.
Lee June (retsyo) raised the priority of this task from to Needs Triage by Developer.

It is necessary to perform deselecting of all in EDIT mode before choosing something.
You should choose a necessary thing in OBJECT mode afterwards.
For example, in this way.

import bpy

C = bpy.context

bpy.ops.object.select_all(action='DESELECT')
for ob in bpy.data.objects:
    if ob.type == 'MESH':
        C.scene.objects.active = ob
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.mesh.select_all(action='DESELECT')
        bpy.ops.object.mode_set(mode='OBJECT')
        ob.data.vertices[0].select = True
Campbell Barton (campbellbarton) closed this task as Invalid.

This is caused by selection flushing on changing modes.

If you remove all edges and faces the examples work as expected.

You can either set the edge and face selection states. or use the BMesh API which has selection flushing functions.

http://www.blender.org/api/blender_python_api_2_76_release/bmesh.types.html#bmesh.types.BMesh.select_flush

closing.