Sub topic 4
Edit Mode: working with mesh geometry
This chapter assumes you can open Blender with the default scene, navigate the 3D Viewport, select objects, and use Move, Rotate, and Scale. It also assumes you know that a mesh is built from vertices, edges, and faces. Basic Python is needed only for the code examples.
What Edit Mode changes
In Object Mode you work on whole objects. You move a cube, rotate a lamp, or scale a sphere. Edit Mode works one level lower. It gives you access to the mesh data, which is the list of vertices, edges, and faces that defines the shape of the object.
An object in Blender is a container. It holds a transform (location, rotation, scale) and a link to a data block. For a mesh object, that data block is a Mesh. The same Mesh can be shared by several objects, so Edit Mode changes the shape for every object that uses it.
| Question | Object Mode | Edit Mode |
|---|---|---|
| What do you select? | Whole objects | Vertices, edges, faces |
| What do Move, Rotate, Scale change? | The object's transform | Positions of the selected geometry |
| Where is the change stored? | On the object | In the mesh data |
| Does it affect linked copies? | No, each object has its own transform | Yes, all objects sharing the mesh change |
Entering and leaving Edit Mode
Select a mesh object and press Tab in the 3D Viewport. The header changes and the mesh shows its vertices, edges, and faces. Press Tab again to return to Object Mode.
You can also use the mode menu at the left of the 3D Viewport header. Edit Mode is only offered for object types that have editable geometry, such as meshes, curves, surfaces, and text. A camera or a light has no Edit Mode, so Tab does nothing useful for them.
The following script reads the current mode and switches between modes with the mode_set operator.
import bpy
obj = bpy.context.active_object
if obj is not None and obj.type == 'MESH':
print(obj.mode) # 'OBJECT' or 'EDIT', and so on
bpy.ops.object.mode_set(mode='EDIT')
print(obj.mode) # 'EDIT'
bpy.ops.object.mode_set(mode='OBJECT')
print(obj.mode) # 'OBJECT'The operator needs a valid active object and a suitable context. If you run it from a place where no 3D Viewport context exists, it can fail with a context error. Running the script from the Text Editor inside Blender normally works.
Select modes: vertex, edge, and face
Inside Edit Mode you choose what kind of element you pick with a click. The three select modes are:
- Vertex: you pick single points. Shortcut
1. - Edge: you pick the lines between points. Shortcut
2. - Face: you pick whole polygons. Shortcut
3.
The shortcuts are the number keys on the main keyboard row, with the mouse over the 3D Viewport. The three buttons also sit in the header.
Switching select mode does not change the mesh. It changes what a click selects and how the current selection is converted. Going from vertex to face mode keeps only faces whose vertices are all selected. Going from face to vertex mode selects the corner vertices of the selected faces.
Hold Shift while clicking a select-mode button to enable more than one mode at once. This is useful when you want to pick a single vertex and then an edge without switching back and forth.
Working with the selection
Common selection actions in Edit Mode:
- Click to select one element.
Shift+click adds to or removes from the selection. Aselects all, andAlt+Adeselects all.- Box select, circle select, and lasso select work as they do in Object Mode, but on mesh elements.
Alt+click on an edge selects an edge loop.Alt+click on a face selects a face loop in face mode.Ctrl+Iinverts the selection.
Move (G), Rotate (R), and Scale (S) work on the selected elements. The pivot point setting decides what they rotate and scale around. With the default Median Point, scaling a selected face shrinks or grows it around its own center.
Object-level changes compared with mesh-level changes
This difference causes many beginner errors. Moving the object changes its location. Moving a vertex changes the mesh data. Both look similar in the viewport, but they are stored in different places.
import bpy
obj = bpy.context.active_object
if obj is not None and obj.type == 'MESH':
bpy.ops.object.mode_set(mode='OBJECT')
obj.location.x += 2.0 # object-level change (transform)
obj.data.vertices[0].co.z += 1.0 # data-level change (one vertex)Vertex coordinates are stored in local space, relative to the object's origin. If an object has a scale of 2 and you move a vertex by 1 unit in the mesh data, it appears to move by 2 units in the world. Check the Transform panel (N) in Edit Mode. It can show Local or Global coordinates for the selected elements.
If the object has a non-uniform scale such as (1, 1, 3), later operations such as Bevel and Extrude can give distorted results. Apply the scale in Object Mode with Ctrl+A, then Scale. Applying a transform bakes it into the mesh and resets the object's scale to 1. Do this only on objects that do not share their mesh with another object.
Editing mesh data from Python
The regular obj.data.vertices list is not up to date while the mesh is in Edit Mode. Blender keeps the edit-time geometry in a separate structure. To read or change geometry during Edit Mode, use the bmesh module.
import bpy
import bmesh
obj = bpy.context.edit_object # None unless a mesh is in Edit Mode
if obj is not None and obj.type == 'MESH':
bm = bmesh.from_edit_mesh(obj.data)
for vert in bm.verts:
if vert.select:
vert.co.z += 1.0
bmesh.update_edit_mesh(obj.data)The call to bmesh.update_edit_mesh tells Blender to refresh the viewport and the mesh. If you leave it out, the change may not show until the next update.
If you instead read obj.data.vertices while in Edit Mode, you get the data from the last time the mesh was written out, which is usually the moment you entered Edit Mode. Leave Edit Mode first, or use BMesh.
Editing several objects at once
Blender can put several objects into Edit Mode together. Select all the mesh objects you want, make one of them active, and press Tab. All selected objects of the same type enter Edit Mode.
In multi-object editing:
- Each object keeps its own mesh. Selected geometry is tracked per object.
- Transform operations act on the selected geometry from all objects.
- Operators such as Extrude and Delete run on every object that is in Edit Mode.
- Only meshes that share the same type can be edited together. You cannot mix a mesh and a curve.
To add another object to an existing Edit Mode session, Ctrl+click it in the Outliner. This is often faster than leaving Edit Mode, changing the selection, and entering it again.
If two objects share one mesh, they are edited as one set of geometry. A change appears in both.
Useful display options
Two overlays help you read what you are editing:
- Statistics in the Overlays popover shows the counts of selected and total vertices, edges, and faces.
- X-Ray (
Alt+Z) lets you see and select geometry behind other geometry. Without it, box select picks only visible elements. This is a common reason for "missing" selections on the far side of a model.
Common mistakes
- Edits seem to do nothing. You may still be in Object Mode and be moving the whole object. Check the mode menu.
- Only part of the model changes. Hidden geometry is not edited. Press
Alt+Hto reveal it. - Selection does not include the back of the mesh. Turn on X-Ray or orbit around the model.
- A shared mesh changes in several places. The objects use the same data. Make it single-user if you want independent shapes.
- Python reads old coordinates. You are in Edit Mode and reading
obj.data. Use BMesh, or switch to Object Mode first. - Distorted bevels. The object has a non-uniform scale. Apply the scale.
Summary workflow
- In Object Mode, select the object and check its scale.
- Press
Tabto enter Edit Mode. - Pick vertex, edge, or face select mode.
- Select and transform geometry.
- Press
Tabto leave Edit Mode so the changes are written back to the mesh data.
Exercise
You run a script that enters Edit Mode, moves a selected vertex by changing obj.data.vertices[i].co, and then calls bpy.ops.object.mode_set(mode='OBJECT'). The vertex does not end up where you expected. Why, and what should the script use instead?
Show answer
While in Edit Mode, the regular mesh data is not kept in sync with the edit-time geometry. When you leave Edit Mode, Blender writes the edit-time geometry back to the mesh, which overwrites the change made through obj.data.vertices. The script should either change the vertex in Object Mode directly, or use bmesh.from_edit_mesh(obj.data), change vert.co, and call bmesh.update_edit_mesh(obj.data) while in Edit Mode.
Exercise
A cube has a scale of (1, 1, 3). In Edit Mode you move one vertex by 1 unit along its local Z axis. How far does the vertex move in the world, and what would you do before bevelling the cube?
Show answer
It moves 3 units in world space, because the object's scale multiplies local coordinates. Before bevelling, return to Object Mode and apply the scale with Ctrl+A, then Scale, so the scale becomes (1, 1, 1) and the mesh holds the real proportions.