def selected(*args): curves = mc.keyframe(query=True, selected=True, name=True) if not curves: return try: mc.delete(ATTR_FILTER_NAME) except: pass try: mc.delete(OBJ_FILTER_NAME) except: pass filters = list() for c in curves: plug = mc.listConnections(c, plugs=True, source=False, destination=True)[0] print plug filters.append(mc.itemFilter(byName=plug, classification='user')) print filters selectedFilter = mc.itemFilter(union=filters) #mc.delete(filters) print selectedFilter mc.outlinerEditor('graphEditor1OutlineEd', edit=True, attrFilter=selectedFilter)
def createSurfaceShaderItemFilter(): filterText = 'bpj_SurfaceShaderFilter' registeredFilters = cmds.itemFilter(q = 1, listOtherFilters = 1) if registeredFilters: for registeredFilter in registeredFilters: registeredFilterText = cmds.itemFilter(registeredFilter, q = 1, text = 1) # print ('%s --> %s' %(registeredFilter, registeredFilterText)) if registeredFilterText == filterText: cmds.delete(registeredFilter) filter = cmds.itemFilter(text = filterText, secondScript = 'bpj_createSurfaceShaderItemFilterFunction') return filter
def __init__(self): self.setTreeName = 'lightGroupSetTree' self.lgtGrpSetPrefix = 'MtoA_lightGroup_' self.lightGroupNum = 20 self.lightType = mc.itemFilter(byType = ('light','aiAreaLight','aiSkyDomeLight','aiPhotometricLight')) self.setColorList = [[.7,.9,1],[.9,.7,.4],[.8,.3,.1],[.2,.6,.2],[.9,.7,.7],[.2,.5,.9],[1,.35,.3],[.5,.5,.9],[1,.9,.5],[.4,.8,.3]] self.warningColor = [1,.1,.1] # build UI self.ui = self.buildUI()
def setFilter(nameFilter=''): m2nType = cmds.optionVar(q='m2nType') types = [] try: for i in m2nType: type = i.lower() types.append(type) filter = cmds.itemFilter(byType=types) except: filter = cmds.itemFilter(byType=['unknown']) if not nameFilter: nameFilter = cmds.textField('filterText', q=1, tx=1) if nameFilter: name = '*%s*' % nameFilter nFilter = cmds.itemFilter(byName=name) filter = cmds.itemFilter(intersect=(nFilter, filter)) cmds.outlinerEditor('dirList', e=1, filter=filter)
def updateOutliner(self): inputList = cmds.selectionConnection(worldList=True) fromEditor = cmds.selectionConnection(activeList=True) CBcurrText = self.filtersCB.currentText() filterItem = cmds.itemFilter(byType = str(CBcurrText)) cmds.outlinerEditor(self.outlinerName, edit=True, mainListConnection=inputList, filter=filterItem) cmds.outlinerEditor(self.outlinerName, edit=True, selectionConnection=fromEditor)
def loadOutlinerViewsFromXML(self): if not os.path.exists(XML_OUTLINER_CFG_FILE): return tree = None try: tree = xml.etree.ElementTree.parse(XML_OUTLINER_CFG_FILE) except Exception as e: self.ui_errorDialog( 'Error loading user views from file.\nFilename: ' + XML_OUTLINER_CFG_FILE + '\n\n' + 'Additional exception info:\n' + str(e)) def xmlParseBool(s): if s.lower() in ['true', '1', 't', 'y', 'yes']: return True elif s.lower() in ['false', '0', 'f', 'n', 'no']: return False else: self.ui_errorDialog('Error parsing boolean attribute "' + s + '" from file\n' + XML_OUTLINER_CFG_FILE) for view in tree.findall('view'): ov = OutlinerView() if 'name' in view.attrib: ov.name = view.attrib['name'] if 'showShapes' in view.attrib: ov.showShapes = xmlParseBool(view.attrib['showShapes']) if 'showShapesEnable' in view.attrib: ov.showShapesEnable = xmlParseBool( view.attrib['showShapesEnable']) if 'showDagOnly' in view.attrib: ov.showDagOnly = xmlParseBool(view.attrib['showDagOnly']) if 'showSetMembers' in view.attrib: ov.showSetMembers = xmlParseBool(view.attrib['showSetMembers']) if 'showSetMembersEnable' in view.attrib: ov.showSetMembersEnable = xmlParseBool( view.attrib['showSetMembersEnable']) if 'expandObjects' in view.attrib: ov.expandObjects = xmlParseBool(view.attrib['expandObjects']) if 'selectSetMembersEnable' in view.attrib: ov.selectSetMembersEnable = xmlParseBool( view.attrib['selectSetMembersEnable']) filterList = [x.strip(' ,;') for x in view.text.strip().split()] if filterList: ov.filter = m.itemFilter(byType=filterList, text=FILTER_DESC) self.state.outlinerViews.append(ov)
def selected(*args): curves = mc.keyframe(query=True, selected=True, name=True) if not curves: return try: mc.delete(ATTR_FILTER_NAME) except:pass try: mc.delete(OBJ_FILTER_NAME) except:pass filters = list() for c in curves: plug = mc.listConnections(c, plugs=True, source=False, destination=True)[0] print plug filters.append(mc.itemFilter(byName=plug, classification='user')) print filters selectedFilter = mc.itemFilter(union=filters) #mc.delete(filters) print selectedFilter mc.outlinerEditor('graphEditor1OutlineEd', edit=True, attrFilter=selectedFilter)
def updateTextures(txPath, txObjLs=None, updateMaya=True, copy=True): """ Handles copying and updating texture file node paths for incoming txObjLs :param txPath: The directory of the new texture file path. :param txObjLs: A list of objects. :param updateMaya: Updated the file paths in the current scene. :param copy: Makes a copy of the textures to the directory txPath :return: If updateMaya=True: A dictionary of all modified texture file nodes{texture File Node: file path before modification} If updateMaya=False: None """ # txFullPath, txRelPath = txPaths currentPaths = {} if not txObjLs: fileNode = mc.itemFilter(byType='file') fileNodeLs = mc.lsThroughFilter(fileNode) else: txObjLsHist = mc.listHistory(txObjLs, f=True) txObjLsHist = list(set(txObjLsHist)) txObjLsShd = mc.listHistory(txObjLsHist) txObjLsShd = list(set(txObjLsShd)) fileNodeLs = mc.ls(txObjLsShd, type='file') fileNodeLs = list(set(fileNodeLs)) if fileNodeLs: fileNodeLs = list(set(fileNodeLs)) for fileNode in fileNodeLs: if not mc.getAttr('%s.useFrameExtension' % fileNode): filePath = mc.getAttr(fileNode + '.fileTextureName') #getting full path from mayaAttributes oldFilePath = filePath filePath = os.path.expandvars(filePath) if os.path.isfile(filePath): fileName = filePath.split('/')[-1] if copy: shutil.copy(filePath, txPath) if updateMaya: currentPaths[fileNode] = oldFilePath #vray does not support relative path env vars in texures. Until this changes full path is written #mc.setAttr(fileNode + '.fileTextureName', os.path.join(txRelPath, fileName), type='string') mc.setAttr(fileNode + '.fileTextureName', os.path.join(txPath, fileName), type='string') if updateMaya: return currentPaths else: return
def loadOutlinerViewsFromXML(self): if not os.path.exists(XML_OUTLINER_CFG_FILE): return tree = None try: tree = xml.etree.ElementTree.parse(XML_OUTLINER_CFG_FILE) except Exception as e: self.ui_errorDialog( 'Error loading user views from file.\nFilename: ' + XML_OUTLINER_CFG_FILE + '\n\n' + 'Additional exception info:\n' + str(e)) def xmlParseBool(s): if s.lower() in ['true', '1', 't', 'y', 'yes']: return True elif s.lower() in ['false', '0', 'f', 'n', 'no']: return False else: self.ui_errorDialog('Error parsing boolean attribute "' + s + '" from file\n' + XML_OUTLINER_CFG_FILE) for view in tree.findall('view'): ov = OutlinerView() if 'name' in view.attrib: ov.name = view.attrib['name'] if 'showShapes' in view.attrib: ov.showShapes = xmlParseBool(view.attrib['showShapes']) if 'showShapesEnable' in view.attrib: ov.showShapesEnable = xmlParseBool(view.attrib['showShapesEnable']) if 'showDagOnly' in view.attrib: ov.showDagOnly = xmlParseBool(view.attrib['showDagOnly']) if 'showSetMembers' in view.attrib: ov.showSetMembers = xmlParseBool(view.attrib['showSetMembers']) if 'showSetMembersEnable' in view.attrib: ov.showSetMembersEnable = xmlParseBool(view.attrib['showSetMembersEnable']) if 'expandObjects' in view.attrib: ov.expandObjects = xmlParseBool(view.attrib['expandObjects']) if 'selectSetMembersEnable' in view.attrib: ov.selectSetMembersEnable = xmlParseBool(view.attrib['selectSetMembersEnable']) filterList = [x.strip(' ,;') for x in view.text.strip().split()] if filterList: ov.filter = m.itemFilter(byType=filterList, text=FILTER_DESC) self.state.outlinerViews.append(ov)
def getTypeNode(nodeType, nodeList): """ Return all the nodes of a specific type from a list of node """ filterName = cmds.itemFilter(byType=nodeType, uniqueNodeNames=True) result = cmds.lsThroughFilter(nodeList, item=filterName) return result
def generateOutlinerViews(self): self.state.outlinerViews = [] # --- DAG Nodes Only --- ov = OutlinerView(name='DAG Nodes', ) self.state.outlinerViews.append(ov) # --- All Objects --- ov = OutlinerView(name='All Nodes', showDagOnly=False) self.state.outlinerViews.append(ov) # --- Shading Groups --- ov = OutlinerView(name='Shading Groups', showSetMembers=False, expandObjects=True, showShapesEnable=False, selectSetMembersEnable=True) ov.filter = m.itemFilter(byType='shadingEngine', text=FILTER_DESC) ov.setFilter = m.itemFilter(text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectSG, ov.selectionConnection) self.state.outlinerViews.append(ov) # --- Materials --- ov = OutlinerView(name='Materials', showDagOnly=False, showShapesEnable=False, showSetMembersEnable=False, selectSetMembersEnable=True) ov.filter = m.itemFilter(byType=[ 'lambert', 'particleCloud', 'anisotropic', 'blinn', 'hairTubeShader', 'layeredShader', 'oceanShader', 'phong', 'phongE', 'rampShader', 'shadingMap', 'surfaceShader', 'useBackground', 'envFog', 'fluidShape', 'lightFog', 'volumeFog', 'volumeShader' ], text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectMatTex, ov.selectionConnection) self.state.outlinerViews.append(ov) # --- Textures --- ov = OutlinerView(name='Textures', showDagOnly=False, showShapesEnable=False, showSetMembersEnable=False, selectSetMembersEnable=True) ov.filter = m.itemFilter(byType=[ 'file', 'mountain', 'cloth', 'water', 'psdFileTex', 'fractal', 'fluidTexture2D', 'grid', 'ramp', 'movie', 'ocean', 'bulge', 'checker', 'noise', 'fluidTexture3D', 'stucco', 'wood', 'snow', 'solidFractal', 'crater', 'volumeNoise', 'brownian', 'granite', 'marble', 'leather', 'cloud', 'rock' ], text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectMatTex, ov.selectionConnection) self.state.outlinerViews.append(ov) # ------------------------------------ self.state.currentView = self.state.outlinerViews[0]
def generateOutlinerViews(self): self.state.outlinerViews = [] # --- DAG Nodes Only --- ov = OutlinerView( name='DAG Nodes', ) self.state.outlinerViews.append(ov) # --- All Objects --- ov = OutlinerView( name='All Nodes', showDagOnly=False ) self.state.outlinerViews.append(ov) # --- Shading Groups --- ov = OutlinerView( name='Shading Groups', showSetMembers=False, expandObjects=True, showShapesEnable=False, selectSetMembersEnable=True ) ov.filter = m.itemFilter(byType='shadingEngine', text=FILTER_DESC) ov.setFilter = m.itemFilter(text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectSG, ov.selectionConnection) self.state.outlinerViews.append(ov) # --- Materials --- ov = OutlinerView( name='Materials', showDagOnly=False, showShapesEnable=False, showSetMembersEnable=False, selectSetMembersEnable=True ) ov.filter = m.itemFilter( byType=['lambert', 'particleCloud', 'anisotropic', 'blinn', 'hairTubeShader', 'layeredShader', 'oceanShader', 'phong', 'phongE', 'rampShader', 'shadingMap', 'surfaceShader', 'useBackground', 'envFog', 'fluidShape', 'lightFog', 'volumeFog', 'volumeShader'], text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectMatTex, ov.selectionConnection) self.state.outlinerViews.append(ov) # --- Textures --- ov = OutlinerView( name='Textures', showDagOnly=False, showShapesEnable=False, showSetMembersEnable=False, selectSetMembersEnable=True ) ov.filter = m.itemFilter( byType=['file', 'mountain', 'cloth', 'water', 'psdFileTex', 'fractal', 'fluidTexture2D', 'grid', 'ramp', 'movie', 'ocean', 'bulge', 'checker', 'noise', 'fluidTexture3D', 'stucco', 'wood', 'snow', 'solidFractal', 'crater', 'volumeNoise', 'brownian', 'granite', 'marble', 'leather', 'cloud', 'rock'], text=FILTER_DESC) ov.selectCommand = ft.partial(self.ui_onOutlinerSelectMatTex, ov.selectionConnection) self.state.outlinerViews.append(ov) # ------------------------------------ self.state.currentView = self.state.outlinerViews[0]
def getShadingGroupsAndTextures(): # shading engines connected to compInstObjGroups[n].compObjectGroups[n] are usually # not assigned to the mesh anymore. # How to recreate this case: # - create a mesh (default lambert shader is assigned (initalShadingGroup)) # - switch to face comp mode and select ALL faces # - assign a new shader to the selected faces # Use the listHistory or listConnections (type = 'shadingEngine') command to see the # initialShadingGroup still being listed as connected to the mesh # while its not assigned to the mesh at all anymore # sel = cmds.ls(sl = 1, long = 0, shapes = 1, dag = 1, noIntermediate = 1, type = ('mesh', 'nurbsSurface', 'subdiv')) sel = cmds.ls(sl = 1, long = 0, shapes = 1, dag = 1, noIntermediate = 1) # TODO: # creating a itemFilter for use with the lsThroughFilter # command to get rid of all non surfaceShape nodes surfaceShapeList = [] validNodes = cmds.ls(sel, type = ['mesh', 'nurbsSurface', 'subdiv']) if len(validNodes) == 0: return None surfaceShapeList.extend(validNodes) shadingEngineList = [] shaderTextureDict = {} fileFilter = cmds.itemFilter(byType = 'file') for item in surfaceShapeList: connections = cmds.listConnections(item, s = 1, plugs = 1, type = 'shadingEngine', skipConversionNodes = 1) if connections: for c in connections: sourcePlug = cmds.connectionInfo(c, sourceFromDestination = 1) if 'compInstObjGroups[' not in sourcePlug: shadingEngineList.append(c.split('.')[0]) shadingEngineList = list(set(shadingEngineList)) if len(shadingEngineList) > 0: for shadingEngine in shadingEngineList: fileNodeList = [] # nodeList = cmds.listHistory(shadingEngine, future = 0, allGraphs = 1) # fileNodeList = cmds.lsThroughFilter(fileFilter, item = nodeList, nodeArray = 1, sort = 'byName') nodeList = cmds.listHistory(shadingEngine, future = False, allGraphs = True, allConnections = False) fileNodeList = cmds.ls(nodeList, exactType = ['file']) # WORKAROUND of a maya bug. Maya is not listing file nodes connected to the vector displacement attr of a displacement node! # So we need to query the connections of the displacement shader (if exists) as well. displacementShaderNodeList = cmds.ls(nodeList, exactType = ['displacementShader']) for dispNode in displacementShaderNodeList: nodeList = cmds.listHistory(dispNode, future = False, allGraphs = True, allConnections = False) fileNodeList.extend(cmds.ls(nodeList, exactType = ['file'])) fileNodeList = list(set(fileNodeList)) shaderTextureDict[shadingEngine] = fileNodeList return shaderTextureDict else: return None cmds.delete(fileFilter)