def run(): """Detect overlapping (lamina) faces. Lamina faces are faces that share all of their edges. --- Returns True/False, the number of isolated vertices and a list of the isolated vertices has_isolatedvertices2() -> (boolean, int, [mesh:v[id],]) """ t0 = float(time.time()) verbose = cmds.optionVar(query='checkmateVerbosity') result=False # meshes = cmds.ls(type='mesh') meshes = [x for x in cmds.ls(typ='mesh', noIntermediate=True) if not cm.tests.shapes.mesh.isEmpty(x)] try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, # all and next type=0x0008, # faces topology=2, # lamina ) sel=cmds.ls(sl=True, fl=True) result = (len(sel) > 0) or False cmds.polySelectConstraint(disable=True) try: cmds.select(sel) except TypeError: pass # print execution time print '%-24s : %.6f seconds' % ('f.lamina.run()', (float(time.time())-t0)) return (result, len(sel), sel)
def run(): """Detect Isolated Vertices. Isolated vertices are the result of deleting edges with Delete rather than with the Delete Edge/Vertex. Using Delete leaves the vertices in place that connected the deleted edge(s). This test ignores vertices on borders, where having such vertices is not a problem. --- returns True/False, the number of isolated vertices and a list of the isolated vertices has_isolatedvertices2() -> (boolean, int, list) """ t0 = float(time.time()) verbose = cmds.optionVar(query='checkmateVerbosity') result=False # meshes = cmds.ls(type='mesh') meshes = [x for x in cmds.ls(typ='mesh', noIntermediate=True) if not cm.tests.shapes.mesh.isEmpty(x)] try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, # all and next type=0x0001, # vertices where=2, # inside order=2, # neighbours orderbound=[2,2] # min and max neighbours ) sel=cmds.ls(sl=True, fl=True) cmds.polySelectConstraint(disable=True) result = (len(sel) > 0) or False print '%-24s : %.6f seconds' % ('vtx.isolated.run()', (float(time.time())-t0)) return (result, len(sel), sel)
def degenerate(): """Detect Isolated Vertices. Isolated vertices are vertices that are not connected to another vertex by two edges. -- returns True/False, the number of isolated vertices and a list of the isolated vertices has_isolatedvertices() -> (boolean, int, [mesh:v[id],]) """ t0 = float(time.time()) verbose = cmds.optionVar(query='checkmateVerbosity') result=False # meshes = cmds.ls(type='mesh') meshes = [x for x in cmds.ls(typ='mesh', noIntermediate=True) if not cm.tests.shapes.mesh.isEmpty(x)] try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, # all and next type=0x0001, # vertices where=2, # inside order=2, # neighbours orderbound=[0,1] # min and max neighbours ) sel=cmds.ls(sl=True, fl=True) cmds.polySelectConstraint(disable=True) result = (len(sel) > 0) or False print '%-24s : %.6f seconds' % ('isolated.run()', (float(time.time())-t0)) return (result, len(sel), sel)
def getTris(q=False): ''' Selects Triangles in Selection Args: q(boolean): if true function returns the selection. Return: result(list): the triangles in the selection ''' cmds.selectMode(co=True) cmds.selectType(smp=False, sme=True, smf=False, smu=False, pv=False, pe=True, pf=False, puv=False) cmds.polySelectConstraint(mode=3, t=0x0008, size=1) cmds.polySelectConstraint(disable=True) nPolys = cmds.polyEvaluate(faceComponent=True) print >> sys.stderr, str(nPolys) + ' Triangles(s) Selected.', if q: result = cmds.ls(sl=True, fl=True) return result
def getFacesInFrustum(container,obj): obj = 'pHelix131' container = 'frust_camera_frustum_geo' # select faces in container(frustum) allVtx = cmds.ls('{0}.vtx[:]'.format(obj),fl=True) allIn = [] for vtx in allVtx: location = cmds.pointPosition(vtx,w=True) test = pyRayIntersect(container,location,(0,1,0)) if(test): allIn.append(vtx) inner_faces = cmds.polyListComponentConversion(allIn,fv=True,tf=True) # select faces that facing the camera cmds.select(obj,r=True) cmds.selectMode(co=True) cmds.selectType(pf=True) cmds.setAttr('{0}.backfaceCulling'.format(obj),2) view = OMU.M3dView.active3dView() OM.MGlobal.selectFromScreen(0, 0, view.portWidth(), view.portHeight(), OM.MGlobal.kReplaceList) facing_cam_faces = cmds.ls(sl=True,fl=True) # combine both selection all_faces = [x for x in cmds.ls(inner_faces,fl=True) if x in cmds.ls(facing_cam_faces,fl=True)] return all_faces
def run(): """Detect faces without uvs. --- Show associated geometry for missingUVS returns True/False, the number of isolated vertices and a list of the isolated vertices has_unmappedfaces() -> (boolean, int, [mesh:v[id],]) """ t0 = float(time.time()) verbose = cmds.optionVar(query='checkmateVerbosity') result=False # meshes = cmds.ls(type='mesh') meshes = [x for x in cmds.ls(typ='mesh', noIntermediate=True) if not cm.tests.shapes.mesh.isEmpty(x)] try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, # all and next type=0x0008, # faces textured=2, # unmapped ) sel=cmds.ls(sl=True, fl=True) result = (len(sel) > 0) or False cmds.polySelectConstraint(disable=True) try: cmds.select(sel) except TypeError: pass # print execution time print '%-24s : %.6f seconds' % ('uv.missing.run()', (float(time.time())-t0)) return (result, len(sel), sel)
def SetVertexColorForBorderVertices(): with mayaUtils.DebugTimer('SetVertexColorForBorderVertices'): skinList = cmds.ls(type='skinCluster') cmds.select(clear=True) for s in skinList: cmds.select(clear=True) mesh = mayaUtils.GetMeshFromSkinCluster(s) cmds.select(mesh) cmds.selectType(polymeshFace=True) cmds.polySelectConstraint(mode=3, type=8, where=1) # to get border vertices borderVerts = cmds.polyListComponentConversion(tv=True) cmds.polySelectConstraint(mode=0, sh=0, bo=0) cmds.select(clear=True) allVerts = cmds.polyListComponentConversion(mesh, tv=True) mayaUtils.SetVertexColors(allVerts, (1, 1, 1)) mayaUtils.SetVertexColors(borderVerts, (0, 1, 1)) cmds.select(clear=True) shape = mayaUtils.FindMeshByWildcard( 'FemaleBody*', checkForMatWithName='Body') #new name is 'Body' if shape: MaskShellsEdgesForTesselation(shape, 0) MaskShellsEdgesForTesselation(shape, 1) MaskShellsEdgesForTesselation(shape, 2) MaskShellsEdgesForTesselation(shape, 3) MaskShellsEdgesForTesselation(shape, 4)
def set_select_types(self, *types): """ replace the existing selection type (face, vertex, etc) with the types supplied. Cache the existing types for later restore """ self.select_type = {k: cmds.selectType(**{'q': 1, k: 1}) for k in ALL_SELECT_TYPES} options = {k: k in types for k in ALL_SELECT_TYPES} cmds.selectType(**options)
def creaseHardEdges(): #crsAmt = 10 crsAmt = cmds.floatSliderGrp('crsAmt', q=True, value=True) cmds.selectType(pe=True) # Selects Edges cmds.polySelectConstraint(m=3, t=0x8000, sm=1) # Constrains selection to hard edges cmds.polyCrease(value=crsAmt) cmds.polySelectConstraint(sm=0) # Turns off contraint
def storeSelectionData (): if RitalinRememberSelections == True: if cmds.undoInfo(q = true, redoName = True) == "": ComponentSelectMode = cmds.selectMode (query = True, component = True) if ComponentSelectMode == True: #print("Storing current component selection...") Sel = cmds.ls(sl = True) hiliteObjs = cmds.ls (hilite = True) if (cmds.selectType (query = True, polymeshVertex = True) == True): if findStoredVertexSelectionTemplate () != None: #print ("Clearing stored vertex selections first...") for obj in hiliteObjs: allVerts = getAllObjVertices(obj) if len(allVerts) > 0: cmds.polyBlindData(allVerts, typeId = 99410, associationType = "vertex", booleanData = False, longDataName = "StoredVertexSelectionData", shortDataName = "SVSD") vertList = list() for cmp in Sel: if cmp.find (obj + ".vtx[") > -1: vertList.append(cmp) #print ("Storing data for currently selected vertices: " + str(vertList)) if len(vertList) > 0: StoredVertexSelectionData = cmds.polyBlindData(vertList, typeId = 99410, associationType = "vertex", booleanData = True, longDataName = "StoredVertexSelectionData", shortDataName = "SVSD") result = cmds.rename ( StoredVertexSelectionData , obj + "_StoredVertexSelectionData") elif (cmds.selectType (query = True, polymeshFace = True) == True): if findStoredFaceSelectionTemplate () != None: #print ("Clearing stored face selections first...") for obj in hiliteObjs: allFaces = getAllObjFaces(obj) if len(allFaces) > 0: cmds.polyBlindData(allFaces, typeId = 99411, associationType = "face", booleanData = False, longDataName = "StoredFaceSelectionData", shortDataName = "SFSD") faceList = list() for cmp in Sel: if cmp.find (obj + ".f[") > -1: faceList.append(cmp) #print ("Storing data for currently selected faces: " + str(faceList) ) if len(faceList) > 0: StoredFaceSelectionData = cmds.polyBlindData(faceList, typeId = 99411, associationType = "face", booleanData = True, longDataName = "StoredFaceSelectionData", shortDataName = "SFSD") result = cmds.rename ( StoredFaceSelectionData , obj + "_StoredFaceSelectionData") elif (cmds.selectType (query = True, polymeshEdge = True) == True): if findStoredEdgeSelectionTemplate () != None: #print ("Clearing stored edge selections first...") for obj in hiliteObjs: allEdges = getAllObjEdges(obj) if len(allEdges) > 0: cmds.polyBlindData(allEdges, typeId = 99412, associationType = "edge", booleanData = False, longDataName = "StoredEdgeSelectionData", shortDataName = "SESD") edgeList = list() for cmp in Sel: if cmp.find (obj + ".e[") > -1: edgeList.append(cmp) #print ("Storing data for currently selected edges: " + str(edgeList) ) if len(edgeList) > 0: StoredEdgeSelectionData = cmds.polyBlindData(edgeList, typeId = 99412, associationType = "edge", booleanData = True, longDataName = "StoredEdgeSelectionData", shortDataName = "SESD") result = cmds.rename( StoredEdgeSelectionData , obj + "_StoredEdgeSelectionData")
def Hardedge_Check(*args): obj = cmds.ls(selection=True) # 存储当前选择物体 cmds.polySelectConstraint(m=3, t=0x8000, sm=1) # 只选择硬边 sel = cmds.ls(selection=True) # 存储选择边 cmds.polySelectConstraint(sm=0) # 还原选zhi择约束 cmds.select(obj) # 还原之前选择的物体 cmds.selectMode(component=True) # 更改选择模式 cmds.selectType(edge=True) # 更改选择项为到边模式 cmds.select(sel) # 选择存储的边
def run(*args, **kwargs): """8a. Extra. Find faces with 0 surface area. These look like edges, but cause shading problems --- returns True/False, the number of 0 area faces and a list of faces. has_zeroareafaces -> (boolean, int, [mesh:f[id],]) """ t0 = float(time.time()) valid_kwargs = ['verbose'] for k, v in kwargs.iteritems(): if k not in valid_kwargs: raise TypeError("Invalid keyword argument %s" % k) result = False err = list() verbose = False # verbose defaults to False if verbose option not set in menu # or specified in cmdline try: verbose = kwargs['verbose'] except KeyError: verbose = False if cmds.optionVar(exists='checkmateVerbosity'): verbose = cmds.optionVar(query='checkmateVerbosity') else: verbose = False result=False meshes = cmds.ls(type='mesh', noIntermediate=True, long=True) if verbose: print 'before: ', meshes meshes = [x for x in meshes if not cm.tests.shapes.mesh.isEmpty(x)] if verbose: print 'after :', meshes try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" if verbose: print 'line 805' cmds.selectType( pf=True ) if verbose: print 'line 807' cmds.polySelectConstraint( mode=3, # all and next type=0x0008, # faces geometricarea=True, geometricareabound = [0.0, 0.00001], # zero area ) if verbose: print 'line 814' sel=cmds.ls(sl=True, fl=True) result = (len(sel) > 0) or False cmds.polySelectConstraint(disable=True) try: cmds.select(sel) except TypeError: pass print '%-24s : %.6f seconds' % ('f.area.run()', (float(time.time())-t0)) return (result, len(sel), sel)
def reset_select_mask(self): """ resets any selection modes set by this tool """ if self.select_mode: cmds.selectMode(**self.select_mode) self.select_mode = None if self.select_type: cmds.selectType(**self.select_type) self.select_type = None
def ngons_on_selected(tris=False): typegon = 'ngons' if tris == True: tris = 1 typegon = 'triangles' else: tris = 3 sel = mc.ls(sl=True) if not sel: sys.exit('Nothing selected !') mc.selectMode(component=True) #Change to Face Component Mode mc.selectType(smp=False, sme=True, smf=False, smu=False, pv=False, pe=False, pf=True, puv=False) #Select Object/s and Run Script to highlight Triangles mc.polySelectConstraint(mode=3, type=0x0008, size=tris) mc.polySelectConstraint(disable=False) ngons = mc.polyEvaluate(faceComponent=True) mc.polySelectConstraint(disable=True) if ngons == 0: print('No ' + str.capitalize(typegon) + ' found !') print('There are ' + str(ngons) + ' ' + str.capitalize(typegon) + ' found on this piece of asset.') if ngons == 1: typegon = typegon[:-1] mc.warning(str(ngons) + ' ' + str(typegon) + ' found.') return ngons
def restoreSelectionData(): if RitalinRememberSelections == True: Sel = cmds.ls(sl = True) #print("Restoring selection..") allHiliteObjsVerts = getAllHiliteObjsVertices() if len(allHiliteObjsVerts) > 0: if (cmds.selectType (query = True, polymeshVertex = True) == True): if findStoredVertexSelectionTemplate () != None: #print ("Restoring vertex selection...") lsStoredVerts = cmds.polyQueryBlindData(allHiliteObjsVerts, sc=True, typeId = 99410, associationType = "vertex", booleanData = True, longDataName = "StoredVertexSelectionData", shortDataName = "SVSD") if lsStoredVerts != None: storedComponents = list() for i in range(0,len(lsStoredVerts)-1,2) : cmp = lsStoredVerts[i].rsplit(".",1)[0]; storedComponents.append(cmp) if len(storedComponents) > 0: #print ("Restoring selection for components: " + str(storedComponents)) cmds.select(storedComponents, add = False) #Replacing selection instead of adding... return allHiliteObjsFaces = getAllHiliteObjsFaces() if len(allHiliteObjsFaces) > 0: if (cmds.selectType (query = True, polymeshFace = True) == True): if findStoredFaceSelectionTemplate () != None: #print ("Restoring face selection...") lsStoredFaces = cmds.polyQueryBlindData(allHiliteObjsFaces, sc=True, typeId = 99411, associationType = "face", booleanData = True, longDataName = "StoredFaceSelectionData", shortDataName = "SFSD") if lsStoredFaces != None: storedComponents = list() for i in range(0,len(lsStoredFaces)-1,2) : cmp = lsStoredFaces[i].rsplit(".",1)[0]; storedComponents.append(cmp) if len(storedComponents) > 0: #print ("Restoring selection for components: " + str(storedComponents)) cmds.select(storedComponents, add = False) #Replacing selection instead of adding... return allHiliteObjsEdges = getAllHiliteObjsEdges() if len(allHiliteObjsEdges) > 0: #print allHiliteObjsEdges if (cmds.selectType (query = True, polymeshEdge = True) == True): if findStoredEdgeSelectionTemplate () != None: #print ("Restoring edge selection...") lsStoredEdges = cmds.polyQueryBlindData(allHiliteObjsEdges, sc=True, typeId = 99412, associationType = "edge", booleanData = True, longDataName = "StoredEdgeSelectionData", shortDataName = "SESD") #print lsStoredEdges if lsStoredEdges != None: storedComponents = list() for i in range(0,len(lsStoredEdges)-1,2) : cmp = lsStoredEdges[i].rsplit(".",1)[0]; storedComponents.append(cmp) if len(storedComponents) > 0: #print ("Restoring selection for components: " + str(storedComponents)) cmds.select(storedComponents, add = False) #Replacing selection instead of adding... return
def ngons(tris=False): typegon = 'ngons' if tris == True: tris = 1 typegon = 'triangles' else: tris = 3 sel = mc.select(ado=True) sel = mc.ls(sl=True) full_sel = [] for each in sel: mc.listRelatives(each, c=True) mc.selectMode(component=True) #Change to Face Component Mode mc.selectType(smp=False, sme=True, smf=False, smu=False, pv=False, pe=False, pf=True, puv=False) #Select Object/s and Run Script to highlight Triangles mc.polySelectConstraint(mode=3, type=0x0008, size=tris) mc.polySelectConstraint(disable=False) ngons = mc.polyEvaluate(faceComponent=True) mc.polySelectConstraint(disable=True) mc.select(cl=True) mc.selectMode(object=True) mc.select(cl=True) if ngons == 0: print('No ' + str.capitalize(typegon) + ' found !') print('There are ' + str(ngons) + ' ' + str.capitalize(typegon) + ' found on this asset.') return ngons
def GetBorderVertices(mesh): cmds.select(clear=True) borderVertsList = [] cmds.select(mesh) cmds.selectType(polymeshEdge=True) cmds.polySelectConstraint(mode=3, type=0x8000, where=1) # to get border vertices borderVerts = cmds.polyListComponentConversion(tv=True) borderVertsList.extend(borderVerts) cmds.polySelectConstraint(mode=0, sh=0, bo=0) cmds.select(clear=True) return borderVertsList
def three(self): if cmds.selectMode ( query = 1, object = 1): cmds.selectMode ( component = 1) self.selectionMask( 'face' ) else: # select mode is set to component if self.getType(0) == 'vertex' or self.getType(0) == 'edge': cmds.select(self.convertSelection('face')) self.selectionMask( 'face' ) else: if cmds.selectType( query = 1, polymeshFace = True): cmds.selectMode ( object = 1) cmds.selectType( allComponents = False ) else: self.selectionMask( 'face' )
def three(self): if cmds.selectMode(query=1, object=1): cmds.selectMode(component=1) self.selectionMask('face') else: # select mode is set to component if self.getType(0) == 'vertex' or self.getType(0) == 'edge': cmds.select(self.convertSelection('face')) self.selectionMask('face') else: if cmds.selectType(query=1, polymeshFace=True): cmds.selectMode(object=1) cmds.selectType(allComponents=False) else: self.selectionMask('face')
def actuTypeSelection(self): if mc.selectMode(q=True, object=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, select=True) mc.iconTextRadioButton(self.bt_selVert, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selEdge, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selFace, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selUv, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selMulti, edit=True, enableBackground=False) else: if mc.selectType(q=True, vertex=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selVert, edit=True, select=True) mc.iconTextRadioButton(self.bt_selEdge, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selFace, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selUv, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selMulti, edit=True, enableBackground=False) if mc.selectType(q=True, edge=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selVert, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selEdge, edit=True, select=True) mc.iconTextRadioButton(self.bt_selFace, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selUv, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selMulti, edit=True, enableBackground=False) if mc.selectType(q=True, facet=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selVert, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selEdge, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selFace, edit=True, select=True) mc.iconTextRadioButton(self.bt_selUv, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selMulti, edit=True, enableBackground=False) if mc.selectType(q=True, meshComponents=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selVert, edit=True, backgroundColor=self.selectColor) mc.iconTextRadioButton(self.bt_selEdge, edit=True, backgroundColor=self.selectColor) mc.iconTextRadioButton(self.bt_selFace, edit=True, backgroundColor=self.selectColor) mc.iconTextRadioButton(self.bt_selUv, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selMulti, edit=True, select=True) if mc.selectType(q=True, polymeshUV=True): mc.iconTextRadioButton(self.bt_selObj, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selVert, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selEdge, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selFace, edit=True, enableBackground=False) mc.iconTextRadioButton(self.bt_selUv, edit=True, select=True) mc.iconTextRadioButton(self.bt_selMulti, edit=True, enableBackground=False)
def checkTriangle (self, *args): cmds.select(cmds.ls(type="mesh")) # to get triangles cmds.selectMode( co=True ) cmds.selectType( pf=True ) cmds.polySelectConstraint( m=3, t=8, sz=1 ) components = cmds.ls(sl=True) self.updateButton(components, self.widgets['checkTriangle_button'], self.widgets['selectTriangle_button']) cmds.polySelectConstraint( sz=0 ) # turn off face size constraint cmds.selectMode( o=True ) return components
def checkNonTriangulatable (self, *args): cmds.select(cmds.ls(type="mesh")) # to get triangles cmds.selectMode( co=True ) cmds.selectType( pf=True) cmds.polySelectConstraint( m=3, t=8, tp=1 ) components = cmds.ls(sl=True) self.updateButton(components, self.widgets['checkNonTriangulatable_button'], self.widgets['selectNonTriangulatable_button']) cmds.polySelectConstraint( tp=0 ) # turn off the face topology constraint cmds.selectMode( o=True ) return components
def enableObjectVertexSelection(item): ''' Enable vertex selection for specified object @param item: Object to switch selection mode for @type item: str ''' # Hilite item mc.hilite(item) # Get item type itemType = mc.objectType(mc.listRelatives(item, s=1, ni=1)[0]) # Set selection mode if itemType == 'mesh': mc.selectType(ocm=1, vertex=1) if itemType == 'nurbsSurface' or itemType == 'nurbsCurve': mc.selectType(ocm=1, controlVertex=1)
def enableObjectVertexSelection(item): ''' Enable vertex selection for specified object @param item: Object to switch selection mode for @type item: str ''' # Hilite item mc.hilite(item) # Get item type itemType = mc.objectType(mc.listRelatives(item,s=1,ni=1)[0]) # Set selection mode if itemType == 'mesh': mc.selectType(ocm=1,vertex=1) if itemType == 'nurbsSurface' or itemType == 'nurbsCurve': mc.selectType(ocm=1,controlVertex=1)
def one(self): if cmds.selectMode ( query = 1, object = 1): cmds.selectMode ( component = 1) self.selectionMask( 'vertex' ) else: # select mode is set to component if self.getType(0) == 'face' or self.getType(0) == 'edge': # Check to see if another component is alread selected # This will switch the selection over cmds.select(self.convertSelection('vertex')) self.selectionMask( 'vertex' ) else: if cmds.selectType( query = 1, polymeshVertex = True): cmds.selectMode ( object = 1) cmds.selectType( allComponents = False ) else: self.selectionMask( 'vertex' )
def one(self): if cmds.selectMode(query=1, object=1): cmds.selectMode(component=1) self.selectionMask('vertex') else: # select mode is set to component if self.getType(0) == 'face' or self.getType(0) == 'edge': # Check to see if another component is alread selected # This will switch the selection over cmds.select(self.convertSelection('vertex')) self.selectionMask('vertex') else: if cmds.selectType(query=1, polymeshVertex=True): cmds.selectMode(object=1) cmds.selectType(allComponents=False) else: self.selectionMask('vertex')
def S(self): if cmds.currentCtx() == 'polySlideEdgeContext': cmds.setToolTo ('polySelectEditContext') elif cmds.currentCtx() == 'polySelectEditContext': cmds.setToolTo ('polySlideEdgeContext') else: if self.getType(0) == 'edge': try: self.bridgeTool() except RuntimeError: cmds.setToolTo('polySlideEdgeContext') elif cmds.selectType(q=1, polymeshVertex = True) == True: #check to see if mask type is vertex self.vertexMergeTool() elif self.getType(0) == 'face': self.chipFacesTool() elif self.getType(0) == 'mesh': if len(self.getSelection()) == 1: self.polySeperateTool() # seperate because there's only one poly selected else: self.polyMergeTool() # merge because there's more than one poly selected elif self.getType(0)[0] == 'camera': print 'yes it is' self.cameraShakeTool() else: cmds.setToolTo ('polySelectEditContext')
def S(self): if cmds.currentCtx() == 'polySlideEdgeContext': cmds.setToolTo('polySelectEditContext') elif cmds.currentCtx() == 'polySelectEditContext': cmds.setToolTo('polySlideEdgeContext') else: if self.getType(0) == 'edge': try: self.bridgeTool() except RuntimeError: cmds.setToolTo('polySlideEdgeContext') elif cmds.selectType( q=1, polymeshVertex=True ) == True: #check to see if mask type is vertex self.vertexMergeTool() elif self.getType(0) == 'face': self.chipFacesTool() elif self.getType(0) == 'mesh': if len(self.getSelection()) == 1: self.polySeperateTool( ) # seperate because there's only one poly selected else: self.polyMergeTool( ) # merge because there's more than one poly selected elif self.getType(0)[0] == 'camera': print 'yes it is' self.cameraShakeTool() else: cmds.setToolTo('polySelectEditContext')
def get_active_flags_in_mask(object=True): """ Return dict object with current state of flags in selection mask. """ object_flags = [ 'handle', 'ikHandle', 'ikEndEffector', 'joint', 'light', 'camera', 'lattice', 'cluster', 'sculpt', 'nonlinear', 'nurbsCurve', 'nurbsSurface', 'curveOnSurface', 'polymesh', 'subdiv', 'stroke', 'plane', 'particleShape', 'emitter', 'field', 'fluid', 'hairSystem', 'follicle', 'nCloth', 'nRigid', 'dynamicConstraint', 'nParticleShape', 'collisionModel', 'spring', 'rigidBody', 'rigidConstraint', 'locatorXYZ', 'orientationLocator', 'locatorUV', 'dimension', 'texture', 'implicitGeometry', 'locator', 'curve' ] component_flags = [ 'controlVertex', 'hull', 'editPoint', 'polymeshVertex', 'polymeshEdge', 'polymeshFreeEdge', 'polymeshFace', 'polymeshUV', 'polymeshVtxFace', 'vertex', 'edge', 'facet', 'curveParameterPoint', 'curveKnot', 'surfaceParameterPoint', 'surfaceKnot', 'surfaceRange', 'surfaceEdge', 'surfaceFace', 'surfaceUV', 'isoparm', 'subdivMeshPoint', 'subdivMeshEdge', 'subdivMeshFace', 'subdivMeshUV', 'latticePoint', 'particle', 'springComponent', 'jointPivot', 'scalePivot', 'rotatePivot', 'selectHandle', 'localRotationAxis', 'imagePlane', ] flag_list = object_flags if object else component_flags return [i for i in flag_list if cmds.selectType(q=True, **{i: True})]
def object_mode(): """ Perform a task in object mode then restores mode to previous. """ try: object_mode = cmds.selectMode(q=True, object=True) if not object_mode: current_mode = get_active_select_mode() cmds.selectMode(object=True) object_flags = get_active_flags_in_mask(object=True) cmds.selectType(allObjects=True) yield finally: cmds.selectType(**{k: True for k in object_flags}) if not object_mode: cmds.selectMode(**{current_mode: True})
def component_mode(): """ Perform a task in component mode then restore to previous mode. """ try: component_mode = cmds.selectMode(q=True, component=True) if not component_mode: current_mode = get_active_select_mode() cmds.selectMode(component=True) component_flags = get_active_flags_in_mask() cmds.selectType(allCoponents=True) yield finally: cmds.selectType(**{k: True for k in component_flags}) if not component_mode: cmds.selectMode(**{current_mode: True})
def createJointAtPoint(radius=30): sel = cmds.ls(sl=1) hi = cmds.ls(hilite=1)[0] vtx = cmds.filterExpand(sm=31) pos = [0.0,0.0,0.0] for v in vtx: p = cmds.xform(v, q=1, t=1, ws=1) for i in range(3): pos[i] = pos[i] + p[i] for i in range(3): pos[i] = pos[i] / len(vtx) cmds.select(d=1) cmds.joint(p=pos, radius=radius) cmds.isolateSelect('modelPanel4',addSelected=1) cmds.select(hi) cmds.hilite(replace=1) cmds.selectType(ocm=1,vertex=1)
def straightenVertsFromUI(): """ Straighten Vertices From UI """ # Get Edge Selection sel = cmds.ls(sl=True, fl=True) edges = cmds.filterExpand(sel, ex=True, sm=32) verts = cmds.filterExpand(sel, ex=True, sm=31) if not edges and verts: cmds.select(verts) mel.eval('ConvertSelectionToContainedEdges') edges = cmds.filterExpand(ex=True, sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = cmds.ls(edges, o=True) # Get UI Parameters falloff = cmds.floatSliderGrp('straightenVerts_falloffFSG', q=True, value=True) edgeSpacing = cmds.checkBoxGrp('straightenVerts_edgeSpacingCBG', q=True, v1=True) snapToOrig = cmds.checkBoxGrp('straightenVerts_snapToOrigCBG', q=True, v1=True) delHistory = cmds.checkBoxGrp('straightenVerts_deleteHistoryCBG', q=True, v1=True) # Straighten Vertices straightenVerts(edgeList=edges, falloff=falloff, keepEdgeSpacing=edgeSpacing, snapToOriginal=snapToOrig, deleteHistory=delHistory) # Restore Selection if sel: cmds.selectMode(component=True) cmds.selectType(edge=True) cmds.hilite(mesh) cmds.select(edges)
def ngonFaces(): selNGonObj = mc.ls(sl=True) if len(selNGonObj): mc.selectMode(co=True) mc.selectType(smp=False, sme=True, smf=False, smu=False, pv=False, pe=True, pf=False, puv=False) mc.polySelectConstraint(m=3, type=0x0008, size=3) mc.polySelectConstraint(disable=True) getTriFaces = mc.polyEvaluate(fc=True) print('You have %i ngon(s) in your mesh' % (getTriFaces)) else: print('Please select a polygonal object')
def pre_pro_reference(sel=None): global pre_ref_mode, pre_sel, ctx_mode, pre_obj_list if cmds.selectMode(q=True, o=True): pre_ref_mode = "object" else: prej_ref_mode = "component" if cmds.selectType(q=True, pv=True): pre_ref_mode = "vertex" if cmds.selectType(q=True, pe=True): pre_ref_mode = "edge" if cmds.selectType(q=True, pf=True): pre_ref_mode = "face" pre_sel = sel if cmds.selectMode(q=True, co=True): cmds.selectMode(o=True) pre_obj_list = cmds.ls(sl=True, l=True) cmds.selectMode(co=True) return pre_ref_mode
def pre_pro_reference(sel=None): global pre_ref_mode, pre_sel, ctx_mode, pre_obj_list if cmds.selectMode(q=True, o=True): pre_ref_mode = 'object' else: prej_ref_mode = 'component' if cmds.selectType(q=True, pv=True): pre_ref_mode = 'vertex' if cmds.selectType(q=True, pe=True): pre_ref_mode = 'edge' if cmds.selectType(q=True, pf=True): pre_ref_mode = 'face' pre_sel = sel if cmds.selectMode(q=True, co=True): cmds.selectMode(o=True) pre_obj_list = cmds.ls(sl=True, l=True) cmds.selectMode(co=True) return pre_ref_mode
def doCheck(self): # Clean out existing vars to start a new detection self.emptyUVs = [] unMapLim = 0 unMapCount = 0 unMapRep = '' # Array for holding polygons and their faces polyHold = cmds.ls(geometry=True) faceHold = cmds.polyListComponentConversion(polyHold, tf=True) # Saving the selection and hilite states userHil = cmds.ls(hilite=True) userSel = cmds.ls(selection=True) # Selecting the faces for contraint cmds.select(faceHold) # Constraining the selection to any faces that are unmapped cmds.polySelectConstraint(mode=3, type=8, textured=2) self.emptyUVs = cmds.ls(selection=True) unMapLim = len(self.emptyUVs) # Clearing out the selections cmds.polySelectConstraint(disable=True) cmds.select(clear=True) # Counting up the faces found to be unmapped for i in range(0, unMapLim): cmds.select(self.emptyUVs[i]) unMapCount += cmds.polyEvaluate(self.emptyUVs[i], faceComponent=True) # Restoring the original selection state cmds.selectType(allObjects=True) cmds.hilite(userHil) cmds.select(userSel) # Determining if any unmapped faces have been found and reporting if self.emptyUVs: unMapRep = '%d unmapped faces detected.' % (unMapCount) return unMapRep
def evenEdgeSpacingFromUI(): """ Even Edge Spacing From UI """ # Get Edge Selection sel = cmds.ls(sl=True, fl=True) edges = cmds.filterExpand(sel, ex=True, sm=32) verts = cmds.filterExpand(sel, ex=True, sm=31) if not edges and verts: cmds.select(verts) mel.eval('ConvertSelectionToContainedEdges') edges = cmds.filterExpand(ex=True, sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = cmds.ls(edges, o=True) # Get UI Parameters smooth = cmds.intSliderGrp('evenEdgeSpacing_smoothISG', q=True, v=True) influence = cmds.floatSliderGrp('evenEdgeSpacing_influenceFSG', q=True, v=True) snapToOrig = cmds.checkBoxGrp('evenEdgeSpacing_snapToOrigCBG', q=True, v1=True) delHistory = cmds.checkBoxGrp('evenEdgeSpacing_deleteHistoryCBG', q=True, v1=True) # Even Edge Spacing evenEdgeSpacing(edgeList=edges, smooth=smooth, influence=influence, snapToOrig=snapToOrig, deleteHistory=delHistory) # Restore Selection if sel: cmds.selectMode(component=True) cmds.selectType(edge=True) cmds.hilite(mesh) cmds.select(edges)
def on_changed_callback(raw_command, state): """New callback""" # If "control" is held force the toggled one to on and # toggle the others based on whether any of the buttons # was remaining active after the toggle, if not then # enable all if mc.getModifiers() == 4: # = CTRL state = True active = [mc.iconTextCheckBox(btn, query=True, value=True) for btn in buttons] if any(active): mc.selectType(allObjects=False) else: mc.selectType(allObjects=True) # Replace #1 with the current button state cmd = raw_command.replace(" #1", " {}".format(int(state))) mel.eval(cmd)
def getNgons(q=False): '''Selects Ngons in Selection Args: q(boolean): if true fucntion returns the selection. Return: result(list): the NGons in selection ''' cmds.selectMode(co=True) cmds.selectType(smp=False, sme=True, smf=False, smu=False, pv=False, pe=True, pf=False, puv=False) cmds.polySelectConstraint(mode=3, t=0x0008, size=3) cmds.polySelectConstraint(disable=True) nPolys = cmds.polyEvaluate(faceComponent=True) print >> sys.stderr, str(nPolys) + ' N-Gon(s) Selected.', if q: result = cmds.ls(sl=True, fl=True) return result
def smoothEdgeLineFromUI(): ''' Smooth Edge Line From UI ''' # Get Edge Selection sel = mc.ls(sl=True, fl=True) edges = mc.filterExpand(sel, ex=True, sm=32) verts = mc.filterExpand(sel, ex=True, sm=31) if not edges and verts: mc.select(verts) mm.eval('ConvertSelectionToContainedEdges') edges = mc.filterExpand(ex=True, sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = mc.ls(edges, o=True) # Get UI Parameters smooth = mc.intSliderGrp('smoothEdges_smoothISG', q=True, v=True) falloff = mc.floatSliderGrp('smoothEdges_falloffFSG', q=True, v=True) edgeSpacing = mc.checkBoxGrp('smoothEdges_edgeSpacingCBG', q=True, v1=True) snapToOrig = mc.checkBoxGrp('smoothEdges_snapToOrigCBG', q=True, v1=True) delHistory = mc.checkBoxGrp('smoothEdges_deleteHistoryCBG', q=True, v1=True) # Smooth Edges smoothEdgeLine(edges, smooth=smooth, falloff=falloff, snapToOrig=snapToOrig, keepEdgeSpacing=edgeSpacing, deleteHistory=delHistory) # Restore Selection if sel: mc.selectMode(component=True) mc.selectType(edge=True) mc.hilite(mesh) mc.select(edges)
def nonquads(ngons=True, query=False): """ Select all nonquads from an object. """ type_ = 3 if ngons else 1 if query: selected = mampy.daglist() cmds.selectMode(component=True) cmds.selectType(facet=True) cmds.polySelectConstraint(mode=3, t=0x0008, size=type_) cmds.polySelectConstraint(disable=True) ngons = mampy.daglist() if query: cmds.select(selected.cmdslist()) return ngons sys.stdout.write(str(len(ngons)) + ' N-Gon(s) Selected.\n')
def advanceMoveMulti(): """ same as advanceMove but with multicomponents enable """ cmds.selectMode(object=True) selection = cmds.ls(sl=True) cmds.selectMode(component=True) cmds.selectMode(object=True) cmds.selectMode(component=True) for node in selection: cmds.delete(node, ch=True) cmds.selectType(meshComponents=True) cmds.hilite(node) cmds.select(clear=True) #mel.eval('dR_selTypeChanged("meshComponents");') activePanel = cmds.getPanel(withFocus=True) cmds.modelEditor(activePanel, e=True, manipulators=False) cmds.setToolTo('moveSuperContext') cmds.selectPref(clickDrag=True)
def mask(sels=[], solo=True, clear=False): allowed_types = [ 'baseLattice', 'clusterHandle', 'deformBend', 'deformSquash', 'follicle', 'ikHandle', 'joint', 'lattice', 'locator', 'mesh', 'nurbsCurve', 'nurbsSurface' ] s_types = set() sels = get_sels(sels, error=False) if sels and not clear: for sel in sels: s_types.add(node_type(sel)) s_types = s_types.intersection(allowed_types) if s_types: if solo: cmds.selectType(allObjects=not solo) #byName flag not working correctly. using mel.eval instead. try: mel.eval('selectType -byName gpuCache %i' % (not solo)) except: pass for s_type in s_types: if s_type == 'baseLattice': s_type = 'lattice' elif s_type == 'clusterHandle': s_type = 'cluster' elif s_type == 'deformBend' or s_type == 'deformSquash': s_type = 'nonlinear' elif s_type == 'mesh': s_type = 'polymesh' elif s_type == 'nurbsSurface': s_type = 'nurbsSurface' eval('cmds.selectType(%s=%s)' % (s_type, solo)) else: cmds.selectType(allObjects=True) try: mel.eval('selectType -byName gpuCache true') except: pass return
def get_ngons(objects=None): """ This gets all N-Gons from the given objList. :param list objects: List of objects you want the N-Gons from. If this is None the current User-selection will be used. :returns: a list of n-gons :rtype: list of str """ if objects is None: objects = [] with util.UserSelection(): if objects: cmds.select(objects) cmds.selectMode(component=True) cmds.selectType(allComponents=0, polymeshFace=1) cmds.polySelectConstraint(mode=3, type=0x0008, size=3) cmds.polySelectConstraint(mode=0, size=0) ngons = cmds.ls(selection=True, long=True) return ngons
def get_lamina_faces(objects=None): """ This gets all lamina faces from the given objList. :param list objects: List of objects you want the lamina faces from. If this is None the current selection will be used. :returns: a list of lamina faces :rtype: list of str """ if objects is None: objects = [] with util.UserSelection(): if objects: cmds.select(objects) cmds.selectMode(component=True) cmds.selectType(allComponents=0, polymeshFace=1) cmds.polySelectConstraint(mode=3, type=0x0008, topology=2) cmds.polySelectConstraint(mode=0, topology=0) lamina = cmds.ls(selection=True, long=True) return lamina
def get_non_manifold_vertices(objects=None): """ This gets all non-manifold vertices from the given objList. :param list objects: List of objects you want the non-manifold vertices from. If this is None the current selection will be used. :returns: a list of non-manifold-vertices :rtype: list of str """ if objects is None: objects = [] with util.UserSelection(): if objects: cmds.select(objects) cmds.selectMode(component=True) cmds.selectType(allComponents=0, vertex=1) cmds.polySelectConstraint(mode=3, type=0x0001, nonmanifold=1) cmds.polySelectConstraint(mode=0, nonmanifold=0) nmv = cmds.ls(selection=True, long=True) return nmv
def smoothEdgeLineFromUI(): """ Smooth Edge Line From UI """ # Get Edge Selection sel = cmds.ls(sl=True, fl=True) edges = cmds.filterExpand(sel, ex=True, sm=32) verts = cmds.filterExpand(sel, ex=True, sm=31) if not edges and verts: cmds.select(verts) mel.eval('ConvertSelectionToContainedEdges') edges = cmds.filterExpand(ex=True, sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = cmds.ls(edges, o=True) # Get UI Parameters smooth = cmds.intSliderGrp('smoothEdges_smoothISG', q=True, v=True) falloff = cmds.floatSliderGrp('smoothEdges_falloffFSG', q=True, v=True) edgeSpacing = cmds.checkBoxGrp('smoothEdges_edgeSpacingCBG', q=True, v1=True) snapToOrig = cmds.checkBoxGrp('smoothEdges_snapToOrigCBG', q=True, v1=True) delHistory = cmds.checkBoxGrp('smoothEdges_deleteHistoryCBG', q=True, v1=True) # Smooth Edges smoothEdgeLine(edges, smooth=smooth, falloff=falloff, snapToOrig=snapToOrig, keepEdgeSpacing=edgeSpacing, deleteHistory=delHistory) # Restore Selection if sel: cmds.selectMode(component=True) cmds.selectType(edge=True) cmds.hilite(mesh) cmds.select(edges)
def selectVerts(obj, idx): cmds.selectType(objectComponent=True, allComponents=False) cmds.selectType(objectComponent=True, vertex=True) cmds.selectType(vertex=True) cmds.hilite(obj) if idx is not None: cmds.select('pSphere1.vtx[{0}]'.format(idx), replace=True)
def _decapitate(targets, edges, orig_mesh, index_target=1): """ Takes a lsit of target meshes and deparates them from their bodies so we have isolated head meshes Args: targets [str]: list of target meshes to separate edges [str]: list of edges orig_mesh (str): the original mesh we are replacing from the blends file name index_target (int): used just in case the separate is targetting the wrong index of shell Returns [str]: list of face template meshes created from the targets """ blend_table = {} for edge in [edge for edge in edges if '.' in edge]: transform = edge.split('.')[0] try: blend_table[transform].append(edge) except KeyError: blend_table[transform] = [edge] heads = [] for target in targets: for transform, edges in blend_table.iteritems(): target_shape = mc.listRelatives(target, s=True)[0] edges = [edge.replace(transform, target) for edge in edges] if mc.ls(edges) and len(list(set(mc.ls(edges))))==len(edges): mc.selectMode(co=True) mc.selectType(alc=0, pe=1) mc.select(mc.ls(edges), r=True) mc.polySplitEdge(operation=1, ch=1) shells = mc.polySeparate(target_shape, ch=False) for index, shell in enumerate(shells): if index != index_target: mc.delete(shell) else: shell=shell mc.ungroup(target, w=True) heads.append(shell) mc.selectMode(o=True) return heads
def straightenVertsFromUI(): ''' Straighten Vertices From UI ''' # Get Edge Selection sel = mc.ls(sl=True,fl=True) edges = mc.filterExpand(sel,ex=True,sm=32) verts = mc.filterExpand(sel,ex=True,sm=31) if not edges and verts: mc.select(verts) mm.eval('ConvertSelectionToContainedEdges') edges = mc.filterExpand(ex=True,sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = mc.ls(edges,o=True) # Get UI Parameters falloff = mc.floatSliderGrp('straightenVerts_falloffFSG',q=True,value=True) edgeSpacing = mc.checkBoxGrp('straightenVerts_edgeSpacingCBG',q=True,v1=True) snapToOrig = mc.checkBoxGrp('straightenVerts_snapToOrigCBG',q=True,v1=True) delHistory = mc.checkBoxGrp('straightenVerts_deleteHistoryCBG',q=True,v1=True) # Straighten Vertices straightenVerts( edgeList = edges, falloff = falloff, keepEdgeSpacing = edgeSpacing, snapToOriginal = snapToOrig, deleteHistory = delHistory) # Restore Selection if sel: mc.selectMode(component=True) mc.selectType(edge=True) mc.hilite(mesh) mc.select(edges)
def evenEdgeSpacingFromUI(): ''' Even Edge Spacing From UI ''' # Get Edge Selection sel = mc.ls(sl=True,fl=True) edges = mc.filterExpand(sel,ex=True,sm=32) verts = mc.filterExpand(sel,ex=True,sm=31) if not edges and verts: mc.select(verts) mm.eval('ConvertSelectionToContainedEdges') edges = mc.filterExpand(ex=True,sm=32) if not edges: print('Select a list of connected vertices or edges and run again...') return # Get Mesh from vertices mesh = mc.ls(edges,o=True) # Get UI Parameters smooth = mc.intSliderGrp('evenEdgeSpacing_smoothISG',q=True,v=True) influence = mc.floatSliderGrp('evenEdgeSpacing_influenceFSG',q=True,v=True) snapToOrig = mc.checkBoxGrp('evenEdgeSpacing_snapToOrigCBG',q=True,v1=True) delHistory = mc.checkBoxGrp('evenEdgeSpacing_deleteHistoryCBG',q=True,v1=True) # Even Edge Spacing evenEdgeSpacing( edgeList = edges, smooth = smooth, influence = influence, snapToOrig = snapToOrig, deleteHistory = delHistory ) # Restore Selection if sel: mc.selectMode(component=True) mc.selectType(edge=True) mc.hilite(mesh) mc.select(edges)
def run(*args, **kwargs): """Ngons or n-sided faces are faces with more than 4 edges. This test will fail if any polygonal object contains such a face. The test will also fail if more than 10% of all faces are triangles. --- Detect Ngons? How many? Show/Highlight them. returns True/False and the number of nsided faces in the scene and a list of all n-sided faces has_ngons() -> boolean, int, list, dict, list return (result, len(sel), sel, polyStats, err) """ t0 = float(time.time()) valid_kwargs = ['verbose'] for k, v in kwargs.iteritems(): if k not in valid_kwargs: raise TypeError("Invalid keyword argument %s" % k) # verbose defaults to False if verbose option not set in menu or set # as cmdline argument try: verbose = kwargs['verbose'] except KeyError: verbose = False if cmds.optionVar(exists='checkmateVerbosity'): verbose = cmds.optionVar(query='checkmateVerbosity') else: verbose = False else: pass result=False err = list() polyStats = {'vertexComponent': 0, 'shell': 0, 'triangle': 0, 'faceComponent': 0, 'vertex': 0, 'face': 0, 'triangleComponent': 0, 'edge': 0, 'uvcoord': 0, 'uvComponent': 0, 'edgeComponent': 0, 'tris': 0, 'quads': 0, 'n-sided': 0, } meshes = cmds.ls(type='mesh', noIntermediate=True) meshes = [x for x in cmds.ls(typ='mesh', noIntermediate=True, long=True) if not cm.tests.shapes.mesh.isEmpty(x)] try: cmds.select(meshes) except TypeError: print "# Warning: No meshes in scene" err.append(['#Warning: No meshes in scene']) return (False, 0, [], polyStats, err) polyStats = cmds.polyEvaluate(meshes) scene_faces = polyStats['face'] # selection constraint on mode 3 (all and next) 0x0008(mesh) size 3 (nsided) cmds.selectType( pf=True ) cmds.polySelectConstraint(mode=3, type=0x0008, size=3) cmds.polySelectConstraint( m=3, t=8, sz=3 ) sel=cmds.ls(sl=True, fl=True) cmds.polySelectConstraint(disable=True) result = (len(sel) > 0) or False # tri/quad/n-sided # Tris cmds.select([x for x in cmds.ls(typ='mesh', noIntermediate=True, long=True) if not cm.tests.shapes.mesh.isEmpty(x)]) cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, type=8, size=1 ) # to get triangles scene_triangles = len(cmds.ls(selection=True, flatten=True)) cmds.polySelectConstraint(disable=True) polyStats['tris'] = scene_triangles # Quads cmds.select([x for x in cmds.ls(typ='mesh', noIntermediate=True, long=True) if not cm.tests.shapes.mesh.isEmpty(x)]) cmds.selectType( pf=True ) cmds.polySelectConstraint( mode=3, type=8, size=2 ) scene_quads=len(cmds.ls(selection=True, flatten=True)) polyStats['quads']=scene_quads # N-sided cmds.select([x for x in cmds.ls(typ='mesh', noIntermediate=True, long=True) if not cm.tests.shapes.mesh.isEmpty(x)]) cmds.selectType( pf=True ) if verbose: print 'line 461' cmds.polySelectConstraint( mode=3, type=8, size=3 ) # to get ngons scene_nsided = len(cmds.ls(selection=True, flatten=True)) sel=cmds.ls(sl=True, fl=True) if verbose: print 'line 465' cmds.polySelectConstraint(disable=True) result = (len(sel) > 0) or False polyStats['n-sided']=scene_nsided if verbose: print 'line 469' if verbose: print polyStats if verbose: for k,v in polyStats.iteritems(): print k,v err = list() # if more than 10% of faces are triangles try: trifaceratio = float(scene_triangles)/float(scene_faces) except ZeroDivisionError: trifaceratio = 0.0 if float(scene_triangles)/float(scene_faces) > 0.1 : err.append(['# FAIL: %.2f percent of faces are triangles #' % (trifaceratio*100.0)]) result = True # if there are n-sided faces in the scene if int(scene_nsided) > 1 : err.append(['# FAIL: %d faces are n-sided #' % int(scene_nsided) ]) result = True print '%-24s : %.6f seconds' % ('f.size.run()', (float(time.time())-t0)) return (result, len(sel), sel, polyStats, err)
def shortestEdgePathRelease(): cmds.setToolTo('moveSuperContext') cmds.selectMode(component=True) cmds.selectType(eg=True)
def selectTriangles(): panel = cmds.getPanel(withFocus=True) cmds.modelEditor(panel, e=True, manipulators=False) cmds.selectMode(component=True) cmds.selectType(fc=1) cmds.polySelectConstraint(m=3, t=8, sz=1)