Detect UV island out of limit

Good Morning,
I have a query that I cannot solve, I am trying to detect all the faces of an object that are not within the limit U (0-1) and V (0-1), that is, everything that is outside the red box.

I know it is something simple to do, however I cannot find the command to detect the UV coordinate.

I will be very grateful if you can give me a hint. : D: D Thanks!

Unfortunately blender has no concept of “UV islands” at the api level, but you can easily check if individual coordinates are out of 0,1 space by looking at where they are in UV space. If you’re in edit mode you’ll need to use bmesh.

something like this should be a good starting point:

import bpy, bmesh

obj = bpy.context.active_object
bm = bmesh.from_edit_mesh( obj.data )

uv_layer = bm.loops.layers.uv.active

for face in bm.faces:
    print(f"UVs for face {face.index}")
    for loop in face.loops:
        uv = loop[uv_layer].uv
        print(f"{uv.x}, {uv.y}")
    print("")

Thank you very much for that hint, it works for me for objects with few polygons, for objects with many polygons it takes a long time to calculate.

Thank you very much for your help good man, I will continue investigating how to make this process more optimal. :wink:

A big part of the slowdown is the print statement, remove that and you’ll find that it’s significantly faster.

1 Like