Using Python, Can I querry the red(flipped UVs) in UVEditor?


My artist found an issue where in the UVEditor if you have a single face that is flipped, Red in colored mode, when you run layoutUVs, parts of your mesh will totally scale wrong. Another TA showed us that if you do different selections and in some cases run the layout tool with flip reversed UVs on it eventually works. But this seems haphazard and prone to error. I found some code that allows me to search the entire mesh and determine a flipped UV; however, it takes forever on a large mesh. Is there a way for me to just query the faces, given that the UVEditor already knows which ones are flipped by coloring them?


Morris Olmsted


Mo, what’s the code you’re using currently? cmds? PyMel? Maybe worth porting it over to API code to help improve the speed.


So I tried this with pymel (really slow on dense meshes, components are still a killer).
Tried converting it to cmds, faster, but still over a minute or two for 25k meshes, didn’t want to waste my time trying anything denser.

So popped down to the API, and this will handle a 100k mesh in a few seconds. Might be some more speed to squeeze out of it, but should work well enough for now I think.

from maya.api import OpenMaya as om
from maya import cmds

def unflip():
    face_template = '{0}.f[{1}]'
    sel = om.MGlobal.getActiveSelectionList()
    obj =[0]
    if not sel.length():
        print('Nothing Selected')
    flips = []
    dag = sel.getDagPath(0)
    face_iter = om.MItMeshPolygon(dag)
    for i in xrange(face_iter.count()):
        face = face_iter.setIndex(i)

        uvs = zip(*face_iter.getUVs())
        if not uvs:
        a = uvs[0]
        b = uvs[1]
        c = uvs[2]
        uv_ab = om.MVector(b[0] - a[0], b[1] - a[1])
        uv_bc = om.MVector(c[0] - b[0], c[1] - b[1])
        if (uv_ab ^ uv_bc) * om.MVector(0, 0, 1) <= 0:
            flips.append(face_template.format(obj, i))
    if flips:
        cmds.polyFlipUV(flips, flipType=0, local=True)

Also, no guarantees that I didn’t miss some edge cases.
My quick tests were the opposite of thorough.