Get objects that are not uv

180 views
Skip to first unread message

likage

unread,
Jul 20, 2017, 3:02:49 PM7/20/17
to Python Programming for Autodesk Maya
Hi all,

I have this model in which some of the geometries within are not uv-ed.
As in, you select the geometry >> open up uv editor >> it is blank.

And so it is causing some problems with a script I am doing. Are there any ways in which I can use python to check for such geos with the blank uvs?

FYI, there is only 1 uv set for this model.

Andres Weber

unread,
Jul 20, 2017, 4:04:56 PM7/20/17
to Python Programming for Autodesk Maya
There's probably a hundred ways to do this but here's one:
import pymel.core as pm
sel = pm.ls(sl=True)
sel[0].getShape().getUVs()

>>> ([], []) # This is empty/no UVs
# Or you could do 

sel[0].getShape().map
# or
sel[0].map
# Empty objects should just return something like (depending on object name)
>>> pCubeShape2.map[0]

Interested to see what other people come up with.  For completeness you should probably also check all UV sets just in case...but you mentioned that's not a constraint.

Robert White

unread,
Jul 20, 2017, 4:10:19 PM7/20/17
to Python Programming for Autodesk Maya
If you need to avoid pymel for some reason:

from maya import cmds

def find_unmapped_meshes():
unmapped_meshes = []
for mesh in cmds.ls(type='mesh'):
uvs = cmds.polyListComponentConversion(mesh, toUV=True)
uvs = cmds.ls(uvs, fl=True)
if len(mesh) < 2:
unmapped_meshes.append(mesh)
return unmapped_meshes

Michael Boon

unread,
Jul 24, 2017, 6:55:32 PM7/24/17
to Python Programming for Autodesk Maya
Heh, since we're coming up with alternatives, you can do it in maya.api.OpenMaya too. Once you have the MFnMesh object you can check for uv sets, and also check if the uv sets have uvs:
    uvSets = fnMesh.getUVSetNames()
   
# Note that uvSets can be empty but that is also handled by the any() function.
    if not any(fnMesh.getUVs(uvSet)[0] for uvSet in uvSets):
        unmapped_meshes.append(fnMesh)
Reply all
Reply to author
Forward
0 new messages