12

What is the python way to select vertices of a mesh?

I've tried:

for vert in obj.data.vertices:  
    vert.select = True

I ran the above code in edit mode, but the vertices didn't turn yellow.

sanjeev mk
  • 711
  • 2
  • 8
  • 14

1 Answers1

14
import bpy,bmesh

ob   = bpy.data.objects['Cube']
mesh = bmesh.from_edit_mesh(ob.data)
for v in mesh.verts:
    v.select = True

# trigger viewport update
bpy.context.scene.objects.active = bpy.context.scene.objects.active

Docs

Leander
  • 26,725
  • 2
  • 44
  • 105
stacker
  • 38,549
  • 31
  • 141
  • 243