Sub topic 2
What an interaction mode is
This chapter explains what a mode does in Blender, what it changes, and where Blender stores it. It assumes you can navigate the viewport, select objects, and use Move, Rotate, and Scale. It also assumes you know a mesh is made of vertices, edges, and faces. The Python sections need only basic syntax.
A mode is a state that changes what your input means
An interaction mode is a state of the 3D Viewport that decides what your clicks, keys, and tools act on. The same input can have different effects in different modes. Take the G key (grab) as an example:
- In Object Mode, G moves the selected objects.
- In Edit Mode on a mesh, G moves the selected vertices, edges, or faces of that mesh.
- In Pose Mode on an armature, G moves the selected bones.
Nothing about the key changed. The mode changed what counts as "the thing that is selected."
This is why Blender has modes instead of one editing state. Each kind of work needs its own selection rules, tools, and menus. Keeping them in separate modes lets Blender show only what applies to the work at hand.
What changes when the mode changes
Switching modes changes several things at once.
| Part of the interface | What may change |
|---|---|
| Selection target | Whole objects, or the parts of one object's data (vertices, bones, control points) |
| Header menus | Object Mode shows an **Object** menu. Edit Mode on a mesh shows **Mesh**, **Vertex**, **Edge**, **Face**, and **UV** menus. |
| Toolbar | Different tools are available. Edit Mode has Extrude and Inset, and Sculpt Mode has brushes. |
| Keymap | The same key can run a different operator. |
| Overlays | Edit Mode draws vertices, edges, and face dots over the mesh. |
| Data being modified | The object's transform, or its underlying data (see below) |
Mode does not change what exists in your scene. It only changes what you are currently working on.
Why objects and data need different modes
A mesh object is two things stacked together:
- The object, which holds a name, a transform (location, rotation, scale), modifiers, and a parent.
- The object data, which holds the actual geometry: the vertices, edges, and faces.
Object Mode edits the first layer, and Edit Mode edits the second. Modes exist because these are different kinds of edit. Moving the whole object leaves every vertex coordinate unchanged. Moving one vertex leaves the object's location unchanged. Later chapters cover each mode in detail, and this chapter covers the shared idea.
The mode is stored on the object
The mode is not a single global switch. Each object has its own mode, and you can read it in Python as obj.mode. The viewport also has a current mode, which follows the active object. You read that as bpy.context.mode.
The two values use different strings.
| Situation | `obj.mode` | `bpy.context.mode` |
|---|---|---|
| Any object, Object Mode | `'OBJECT'` | `'OBJECT'` |
| Mesh in Edit Mode | `'EDIT'` | `'EDIT_MESH'` |
| Armature in Pose Mode | `'POSE'` | `'POSE'` |
| Mesh in Sculpt Mode | `'SCULPT'` | `'SCULPT'` |
| Mesh in Weight Paint Mode | `'WEIGHT_PAINT'` | `'PAINT_WEIGHT'` |
Notice that the context string for Edit Mode names the object type (EDIT_MESH, EDIT_CURVE, EDIT_ARMATURE). The object string stays 'EDIT' for all types. Scripts that test for Edit Mode must use the string that matches the value they read.
Because the mode belongs to the object, a saved .blend file remembers it. If you save while a mesh is in Edit Mode, the file reopens with that mesh in Edit Mode.
Mode is tied to the active object
The mode menu in the viewport header acts on the active object, which is the one drawn with a lighter outline. If no object is active, the menu has nothing to act on. The Edit menu has a Lock Object Modes option, on by default. While it is on, clicking an object that cannot enter your current mode does not select it. For example, you cannot click a light while a mesh is in Edit Mode. This prevents accidental mode confusion, and you can turn it off if you want to jump between types without leaving the mode.
Which modes an object can enter
The available modes depend on the object type. An object only offers modes that make sense for its data.
| Object type | Modes available |
|---|---|
| Mesh | Object, Edit, Sculpt, Vertex Paint, Weight Paint, Texture Paint |
| Curve, Surface | Object, Edit |
| Armature | Object, Edit, Pose |
| Lattice | Object, Edit (Weight Paint is available in some cases) |
| Empty, Camera, Light | Object only |
The exact list can differ between Blender versions, so check the mode menu in your own copy. An Empty has no data to edit, so its menu offers no other mode.
Object Mode is the hub. In the interface, you normally go from one mode back through Object Mode, and the mode menu does the transition for you in one step.
Reading the current mode in Python
You can inspect modes without changing anything. This script is safe to run from the Text Editor at any time.
import bpy
print("Viewport mode:", bpy.context.mode)
obj = bpy.context.active_object
if obj is None:
print("No active object")
else:
print(f"{obj.name} is a {obj.type} in mode {obj.mode}")Run it once in Object Mode and once after pressing Tab on a mesh. You will see OBJECT change to EDIT_MESH for the viewport and EDIT for the object.
Changing the mode in Python
The operator bpy.ops.object.mode_set changes the active object's mode. A careful script records the starting mode and restores it afterward, so it does not leave the user in an unexpected state.
import bpy
obj = bpy.context.active_object
if obj is None or obj.type != 'MESH':
raise RuntimeError("Make a mesh object active first")
original = obj.mode
print("start:", original, bpy.context.mode)
bpy.ops.object.mode_set(mode='EDIT')
print("now:", obj.mode, bpy.context.mode) # EDIT EDIT_MESH
bpy.ops.object.mode_set(mode=original)
print("restored:", obj.mode)Common errors
poll() failed, context is incorrect: The full message readsRuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect. It usually means there is no active object, the active object is hidden, or it comes from a linked library file and cannot be edited. Checkbpy.context.active_objectbefore calling the operator.- Requesting a mode the type does not have: Asking an Empty or Camera for Edit Mode fails, because those types have no editable data. Check
obj.typefirst. - Reading stale mesh data: While a mesh is in Edit Mode, changes you make live in a separate edit copy. The regular
obj.data.verticesvalues do not reflect them until you leave Edit Mode. A script that edits a mesh should either switch to Object Mode first or usebmesh.from_edit_mesh, which a later chapter covers. - Assuming the mode string:
'EDIT'and'EDIT_MESH'are different strings. Compareobj.modeagainst'EDIT'andbpy.context.modeagainst'EDIT_MESH'.
Putting the idea together
A mode answers one question: what does my input act on right now? Object Mode targets whole objects through their transforms. Edit Mode targets the geometry inside the active object. Other modes target other things, such as brush strokes, painted weights, or bones. The mode is stored per object, the viewport follows the active object, and the available choices depend on the object type. The next chapters look at Object Mode and Edit Mode one at a time.
Exercise
A mesh object named "Cube" is in Edit Mode. A script prints bpy.context.active_object.mode and bpy.context.mode. What two strings does it print, and why are they different?
Show answer
It prints EDIT and EDIT_MESH. The object's mode string names only the mode and is 'EDIT' for every object type. The viewport (context) mode string includes the object type, so a mesh gives EDIT_MESH, a curve gives EDIT_CURVE, and an armature gives EDIT_ARMATURE.
Exercise
A script calls bpy.ops.object.mode_set(mode='EDIT') and raises poll() failed, context is incorrect. Name three conditions that could cause this, and write the check that prevents the most common one.
Show answer
The conditions are: there is no active object, the active object is hidden, or the active object is linked from a library and not editable. A type with no Edit Mode, such as an Empty, can also cause a failure. The check for the most common one is if bpy.context.active_object is None: followed by selecting or creating an object before calling the operator.