16

Is it possible to switch to vertex mode (and edge, face mode) via python. I know I can toggle between object mode and edit mode in python with

bpy.ops.object.editmode_toggle()

But how can I explicitly say I want to go in vertex mode?

iKlsR
  • 43,379
  • 12
  • 156
  • 189
Miguellissimo
  • 1,355
  • 2
  • 16
  • 29

2 Answers2

18

I prefer to not use operators, if they can be avoided. You may use:

bpy.context.tool_settings.mesh_select_mode

Assign a tuple of 3 booleans to set Vertex, Edge, Face selection.

To activate vertex selection mode, use:

bpy.context.tool_settings.mesh_select_mode = (True, False, False)

For edge + face multi-selection mode, use:

bpy.context.tool_settings.mesh_select_mode = (False, True, True)

etc.


When working with the BMesh Module (bmesh), there's also

bm.select_mode

For edge selection, do:

bm.select_mode = {'EDGE'}

For vertex and face selection multi-mode, do:

bm.select_mode = {'VERT', 'EDGE', 'FACE'}
CodeManX
  • 29,298
  • 3
  • 89
  • 128
17
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_mode(type="FACE")

Look up the operator in the api documentation.

pink vertex
  • 9,896
  • 1
  • 25
  • 44
  • CoDEmanX's solution is much better because the scene doesn't get reloaded. It will be faster and also easier to use of course. – JakeD Sep 30 '16 at 02:33