When working with UV-maps in Blender, sometimes we need to find some boundary points for the entire map. Let’s see how this can be done using the example of finding the left bottom point of the UV-map.
First, switch to object mode to evaluate the data of the UV-map.
|
1 |
bpy.ops.object.mode_set(mode = 'OBJECT') |
Pointer to the currently active UV-map of the mesh.
|
1 2 |
bpy.context.object.data.uv_layers.active # bpy.data.meshes['Cube'].uv_layers["UVMap"] |
Now can get all the “meshloops” – pointers that connect mesh points with its UV-map points.
|
1 2 3 4 |
mesh_loops = [uv_layer.data[loop_index] for _face in bpy.context.object.data.polygons \ for loop_index in _face.loop_indices] # [bpy.data.meshes['Cube'].uv_layers["UVMap"].data[0], bpy.data.meshes['Cube'].uv_layers["UVMap"].data[1], ...] |
Through meshloops we can get coordinates of the UV points.
For example, the coordinates of the first UV point obtained from the first meshloop will be:
|
1 2 3 |
print(mesh_loops[0].uv) # <Vector (1.1929, 0.5230)> |
Having a reference to the coordinates for the meshloop point, we can easily find the bottom left point by first sorting the meshloops by the X coordinate,
|
1 |
mesh_loops_x_sorted = sorted(mesh_loops, key=lambda _uv_point: _uv_point.uv.x) |
and next, finding the meshloop with the minimum Y coordinate.
|
1 |
lb_point = min(mesh_loops_x_sorted, key=lambda _uv_point: _uv_point.uv.y) |
Let’s print the coordinates of the meshloop we found:
|
1 2 3 |
print(lb_point, lb_point.uv) # <bpy_struct, MeshUVLoop at 0x000001BF984FCC30> <Vector (0.2997, 0.0141)> |
As we can visually verify, the coordinates found do correspond to the left bottom point in the mesh UV-map.
Similarly, we can find other boundary points, upper left, lower right, and upper right. We just need to change the sorting by the desired axis (X or Y) and find the minimum or maximum (min() or max()) coordinate by the other axis.

.blend file on Patreon