Advertisement
BigRoyNL

getMeshWithUVsOutRange() @Royn3D

Mar 6th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. """
  2.  
  3. Quick and dirty script to select the mesh shapes from your current selection that have UV shells that are ON the border.
  4. or outside (or on) the range given by the parameters in the script.
  5.  
  6. Written by Roy Nieterau at Colorbleed Animation Studios (www.colorbleed.nl)
  7. For our 'never spoke with this guy before' friend @cgbeige (Dave Girard).
  8.  
  9. Consider this released under the GNU GENERAL PUBLIC LICENSE, use it whenever you like.
  10.  
  11. """
  12. import maya.api.OpenMaya as om2
  13. import maya.cmds as mc
  14.  
  15.  
  16. def getMeshWithUVsOutRange(meshShapes, minU=0.0, maxU=1.0, minV=0.0, maxV=1.0):
  17.    
  18.     # Get a list of all meshes that have UVs out of range
  19.     outsideOfRange = []
  20.     for mesh in meshShapes:
  21.         uvs = om2.MFnMesh(om2.MGlobal.getSelectionListByName(mesh).getDependNode(0)).getUVs()
  22.         if any((u, v) for (u, v) in zip(uvs[0], uvs[1]) if u <= minU or u >= maxU or v <= minV or v >= maxV):
  23.             outsideOfRange.append(mesh)
  24.    
  25.     return outsideOfRange
  26.        
  27.        
  28. if __name__ == "__main__":
  29.  
  30.     # Get all mesh shapes nodes from the selection (note: gets any in the children hierarchy as well)
  31.     shapes = mc.ls(sl=1, dag=1, leaf=1, shapes=1, long=1)
  32.     meshes = mc.ls(shapes, long=1, type="mesh")
  33.    
  34.     outsideOfRange = getMeshWithUVsOutRange(meshes)
  35.  
  36.     # Do something with our filtered result
  37.     if not outsideOfRange:
  38.         print "You're safe. Everything in range!"
  39.     else:
  40.         mc.select(outsideOfRange, r=1)
  41.         print "Darn dude, fix this shit! Check these: {0}".format(outsideOfRange)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement