Sub topic 12
Marking seams faster: sharp edges and scripts
Marking seams one edge at a time works for a simple prop. On a mechanical part with hundreds of edges, it becomes the slowest step of the unwrap. This chapter covers ways to speed it up: selection tools that grab many edges at once, Blender's sharp-edge detection, and short Python scripts.
This chapter assumes you can mark and clear seams in Edit Mode, run UV > Unwrap, and read a checker texture for stretching. It also assumes you can open the Scripting workspace and run a script from the Text Editor. If you have never done the last one, the examples below are short enough to learn on.
Automation gives a starting point
Automatic seams follow geometry, not intent. A script can find every sharp corner on a crate. It cannot know that the back of the crate faces a wall and will never be seen, which is where you would like the cut to go.
Treat every automated result as a first draft:
- Generate seams quickly.
- Unwrap and check the checker texture.
- Remove seams that cut visible areas and add seams where islands still stretch.
Selecting edges quickly before marking them
Before you write any code, Blender's own selection tools handle most of the repetitive work.
- Edge loops. Alt+click an edge to select the whole loop. This is the fastest way to mark a seam around a cylinder or along a panel line.
- Shortest path. Click one vertex, then Ctrl+click another. Blender selects the shortest edge path between them. Tick Tag > Seam in the Adjust Last Operation panel to mark that path as a seam in the same step.
- Select Similar. Select one edge, press Shift+G, and choose a trait such as Sharpness, Seam, Length or Direction. Blender adds every edge that matches.
- Select Sharp Edges. In Edit Mode, choose Select > Select Sharp Edges. It selects edges whose adjacent faces meet at an angle larger than the Sharpness value (30° by default). Raise the value for fewer, harder edges.
After any of these, use Edge > Mark Seam (or Ctrl+E, then Mark Seam) to turn the selection into seams.
Marking Sharp is a different thing from marking a seam
Blender has a separate edge flag called Sharp, set with Edge > Mark Sharp. It controls shading, not UV cutting. A sharp edge is not a seam, and a seam is not a sharp edge. Marking sharp edges for shading and then selecting them with Select Similar > Sharpness is a handy way to reuse that work for seams.
Seams from existing UV islands
The reverse direction also exists. In the UV Editor, select faces and choose UV > Seams from Islands. Blender marks a seam along the border of every island currently shown. This is useful when you shaped islands in the UV Editor, for example with a projection, and want those cuts stored as seams. After that, a later unwrap respects the same cuts.
Marking selected edges with a script
The simplest script marks whatever you have selected. It does the same as Edge > Mark Seam, so on its own it saves nothing. It becomes useful once you add a rule of your own to the loop.
import bpy
import bmesh
obj = bpy.context.edit_object
bm = bmesh.from_edit_mesh(obj.data)
for edge in bm.edges:
if edge.select:
edge.seam = True
bmesh.update_edit_mesh(obj.data)Three details matter here:
bpy.context.edit_objectis only set while the object is in Edit Mode. In Object Mode it isNone, and the script fails with an attribute error.bmesh.from_edit_meshgives you a live view of the mesh being edited. Changes you make are not visible in the viewport until you callbmesh.update_edit_mesh.- Do not call
bm.free()on a mesh you got fromfrom_edit_mesh. Blender owns it. Freeing is only for meshes you created withbmesh.new().
To clear seams instead, set edge.seam = False.
Marking seams by angle
The second script applies a geometric rule. It marks edges where the two neighbouring faces meet at a steep angle, which is a quick start for hard-surface models such as crates, machines and buildings.
import math
import bpy
import bmesh
obj = bpy.context.edit_object
bm = bmesh.from_edit_mesh(obj.data)
threshold = math.radians(60)
for edge in bm.edges:
angle = edge.calc_face_angle(None)
if angle is not None and angle > threshold:
edge.seam = True
bmesh.update_edit_mesh(obj.data)calc_face_angle returns the angle between the two faces that share the edge, in radians. A flat surface gives 0, and a 90° box corner gives about 1.57. The None argument is the fallback value. Edges with only one face, or with more than two, have no meaningful angle. Without a fallback, Blender raises an error for those edges. With None, you get None back and the if test skips them.
Choosing a threshold
The right threshold depends on the model.
| Threshold | Typical result |
|---|---|
| 30° | Many seams. Catches bevels and soft corners, so islands become small and fragmented. |
| 60° | Cuts at box-like corners. A good default for hard-surface models. |
| 80° | Only near-right-angle corners are cut. Curved parts stay connected and may stretch. |
Run the script, then unwrap and check the result. If the islands are too small, raise the threshold. If curved parts stretch, lower it or add manual seams there.
Why this fails on organic meshes
Angle-based seams work because hard-surface models have edges where the shape really changes direction. A character's arm has smooth, gradual curvature. No single edge passes a 60° test, so the script marks almost nothing. The opposite problem appears on high-poly meshes with noisy detail, where many small edges pass the test and the model shatters into tiny islands. For organic shapes, place seams yourself along natural boundaries, such as under the arm or down the back of a leg, and use the script only for small hard parts such as buckles or armour plates.
Bevelled edges can also trip the rule. A 90° corner with a one-segment bevel becomes two 45° edges, and neither passes a 60° threshold. If your angle-based result looks incomplete on a bevelled model, lower the threshold toward 40°.
Running the full chain from a script
Once seams are in place, you can run the unwrap and pack in the same script. This one selects all faces, unwraps along the existing seams with the Angle Based method, packs the islands with a margin, and returns to Object Mode.
import bpy
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.02)
bpy.ops.uv.pack_islands(margin=0.02)
bpy.ops.object.mode_set(mode='OBJECT')Points to watch:
- The
bpy.opscalls depend on context. The active object must be a mesh, ormode_setfails. margin=0.02is a fraction of UV space. It is the gap between islands, which prevents texture bleeding when mipmaps blur the edges.- The unwrap respects seams but does not create them. Run one of the marking scripts first, or the whole mesh is treated as one piece and stretches badly.
- Packing rescales and moves islands. If you need consistent texel density, even it out before packing.
Common errors
AttributeError: 'NoneType' object has no attribute 'data'. There is no object in Edit Mode. Switch to Edit Mode first.- Seams do not appear after the script runs. You skipped
bmesh.update_edit_mesh. Seams appear in the viewport after that call. - ValueError from
calc_face_angle. The edge does not have exactly two faces and you gave no fallback. PassNone. - A seam appears where you did not want one. The script marks every edge that passes the rule. Select the faces or edges you want to process, and add
if edge.selectto the condition.
Exercise
You run the angle-based seam script with a 60° threshold on a smooth, rounded character head. Almost no seams appear. Give the reason, and say what you would do instead.
Show answer
The head's surface curves gradually, so no edge has a face angle above 60°, and the script marks nothing. Angle rules only work where the geometry has real corners. Mark seams by hand along natural boundaries, for example behind the ears and down the back of the head, using edge loops (Alt+click) or shortest-path selection (Ctrl+click) to speed it up. Then unwrap and check the checker texture.
Exercise
A script sets edge.seam = True for the right edges, but nothing changes in the 3D Viewport. Which call is missing?
Show answer
bmesh.update_edit_mesh(obj.data). It writes the BMesh changes back to the edit mesh and refreshes the display.