def getAllShaders(asString=False): """ Returns List of all Shaders from System""" checkAndLoadPlugin("vrayformaya") checkAndLoadPlugin("Mayatomr") maya_shaders = [i for i in pm.listNodeTypes("shader") if "VRay" not in i] mr_shaders = pm.listNodeTypes("rendernode/mentalray") vray_shaders = [i for i in pm.listNodeTypes("shader") if "VRay" in i] if asString: maya_shaders = [str(i) for i in maya_shaders] mr_shaders = [str(i) for i in mr_shaders] vray_shaders = [str(i) for i in vray_shaders] return maya_shaders + mr_shaders + vray_shaders
def getTypeInfo(): ''' return a tuple of NodeClassInfo namedtuples containing (staticClassification, runtimeClassifciation, nodePath, nodeTypes) ''' global _typeInfoMap if not _typeInfoMap : # use a dictionary to get groupings tmpmap = {} nodeTypes = [] for cat in CATEGORIES: catTypes = pm.listNodeTypes('rendernode/arnold/' + cat) if catTypes : nodeTypes.extend(catTypes) if nodeTypes: for nodeType in nodeTypes: (staticClass, runtimeClass, nodePath) = _processClass(nodeType) if staticClass is not None : if staticClass not in tmpmap: tmpmap[staticClass] = [runtimeClass, nodePath, [nodeType]] else: tmpmap[staticClass][2].append(nodeType) # consistent order is important for UIs. build a reliably ordered list. tmplist = [] # known types first. for cat in CATEGORIES: cat = 'rendernode/arnold/' + cat if cat in tmpmap: values = tmpmap.pop(cat) tmplist.append(NodeClassInfo(*([cat] + values))) # custom types in alphabetical order for custom in sorted(tmpmap.keys()): tmplist.append(NodeClassInfo(*([custom] + tmpmap[custom]))) _typeInfoMap = tuple(tmplist) return _typeInfoMap
def renameShadingTrees(base_nodes=[], all_in_scene=False): """Rename the selected Shading tree. need to have shader selected import mo_Utils.mo_shaderUtils as mo_shaderUtils reload(mo_shaderUtils) mo_shaderUtils.renameSelectedShadingTree() """ if all_in_scene: base_nodes = pm.ls(mat=True)[2:] print 'Renaming All Shaders: %s' % base_nodes if base_nodes == []: base_nodes = pm.selected() base_node_type = base_node.nodeType() if base_node_type not in pm.listNodeTypes('shader'): pm.warning( 'No Shader Selected. Please select a shader and try again.') return print 'Renaming Selected: %s' % base_nodes shd_renamer = ShaderRenamer() for base_node in base_nodes: print 'renaming Hierarchy %s' % base_node basename = base_node.replace('_ai', '') shd_renamer.renameShadingTree(base_node, basename, target_attr=None) SG = base_node.connections(t="shadingEngine") if len(SG) > 0: pm.rename(SG[0], base_node + 'SG') shd_renamer.renameShadingTree(SG[0], basename, target_attr=None)
def select_shader(self): self.sender().setStyleSheet( 'QPushButton{color: #00FF00; font-size: 15px; background-color: #300000}' ) select_shader = pm.ls(sl=1) if len(select_shader) == 1 and select_shader[0].type( ) in pm.listNodeTypes('shader'): self.select_shader_btn.setText(select_shader[0].name())
def getSceneLights(self): # returns a list of lights in the scene allLightTypes = pm.listNodeTypes( 'light' ) scene_lights = [] for node in pm.ls(dag=True, s=True, l=True): if node.nodeType() in allLightTypes: scene_lights.append(node) return scene_lights
def append_available_node_categories(self): """ appends available node types in categories Returns: """ available_node_types = self.graph.creation_field.available_items for types in self.configuration.maya.available_node_categories: node_types = pmc.listNodeTypes(types) for node_type in node_types: if not node_type in available_node_types: available_node_types.append(node_type) self.graph.creation_field.available_items = available_node_types
def getShadingNodeTypes(): shader_types = core.listNodeTypes('shader') texture_types = core.listNodeTypes('texture') utility_types = core.listNodeTypes('utility') texture3d_types = core.listNodeTypes('texture/3D') textureenv_types = core.listNodeTypes('texture/Environment') light_types = core.listNodeTypes('light') rendering_types = core.listNodeTypes('rendering') postprocess_types = core.listNodeTypes('postProcess') node_types = { 'shader': shader_types, 'texture': texture_types + texture3d_types + textureenv_types, 'utility': utility_types, 'light': light_types, 'rendering': rendering_types, 'postProcess': postprocess_types } return node_types
def get_window(): global mw try: mw.ui.close() except: pass is_light = 0 lights = list( set(pm.nodeType("shape", derived=True, isTypeName=True)).intersection( pm.listNodeTypes("light"))) for l in pm.ls(type=lights): light = str(l.getParent()) if (len(light) == 8) and ("Light_" in light) and (light[-2:].isdigit()): is_light = 1 else: is_light = 0 break if not is_light: pm.warning( ">> use arnold lights with this naming convention: Light_##") is_camera = 0 for c in pm.ls(type="camera"): camera = str(c.getParent()) if camera not in ["persp", "top", "front", "side"]: is_camera = 1 break if not is_camera: pm.warning(">> could not find render camera in scene") if is_light and is_camera: mw = MyWindow() mw.ui.show()
def collect_materials(self): # Get all materials in the scene. shader_node_types = pm.listNodeTypes('shader') materials = pm.ls(type=shader_node_types) # Collect materials by namespace, and a list of child namespaces in each namespace that # contain materials. self.materials_by_namespace = {} self.namespaces_by_namespace = {} for material in materials: namespace = material.namespace().rstrip(':') # remove trailing : self.materials_by_namespace.setdefault(namespace, []).append(material) # Add this namespace to the parent namespace's list, and add each ancestor # namespace to its parent. If namespaces don't have materials but they have # child namespaces that do, we still need to add them to the list. if namespace: namespace_parts = namespace.split(':') for idx in xrange(1, len(namespace_parts) + 1): child_namespace = ':'.join(namespace_parts[0:idx]) parent_namespace = get_parent_namespace(child_namespace) self.namespaces_by_namespace.setdefault( parent_namespace, set()).add(child_namespace) # The namespace dict used sets to remove duplicates. Replace the sets with lists. self.namespaces_by_namespace = { key: list(value) for key, value in self.namespaces_by_namespace.items() } # Sort each list alphabetically. for material_list in self.materials_by_namespace.values(): material_list.sort(key=lambda node: node.stripNamespace().lower()) for namespace_list in self.namespaces_by_namespace.values(): namespace_list.sort(key=lambda namespace: namespace.lower())
def renameShadingTree(self, base_node, basename, target_attr=None, skip_nodes=['defaultColorMgtGlobals']): print 'renaming' input_plugs = base_node.connections(source=1, d=0, scn=1, plugs=1) node_list = skip_nodes if base_node.nodeType() == 'shadingEngine': input_plugs = base_node.volumeShader.connections( source=1, d=0, scn=1, plugs=1) + base_node.displacementShader.connections( source=1, d=0, scn=1, plugs=1) # check if shader - rename base_node_type = base_node.nodeType() if base_node_type in pm.listNodeTypes('shader'): if base_node_type in self.shaderDic.keys(): pm.rename( base_node, base_node.replace(self.shaderDic[base_node_type], '') + self.shaderDic[base_node_type]) basename = base_node.replace(self.shaderDic[base_node_type], '') else: basename = base_node pm.rename(base_node, base_node + '_%s' % base_node_type) target_attr = None print 'Found shader. Renaming %s. New basename is %s' % (base_node, basename) for input_plug in input_plugs: #print 'input plug is %s'%input_plug #print 'input plugtype is %s'%input_plug.nodeType() node = input_plug.plugNode() node_type = node.nodeType() #print 'node is %s. node_type is %s'%(node, node_type) # rename only if not a shader if node_type not in pm.listNodeTypes('shader'): # skip when already renamed if node in node_list: continue node_list.append(input_plug.plugNode()) # get the attr if not defined yet if target_attr == None: target_attr = input_plug.connections(plugs=1)[0].plugAttr( longName=True) if node_type in self.attributeDic.keys(): node_type = self.attributeDic[node_type] # renaming new_name = '%s_%s_%s01' % (basename, target_attr, node_type) print 'Renaming input plug at %s. Renaming to %s' % ( input_plug, new_name) pm.rename(node, new_name) # recursive for children self.renameShadingTree(node, basename, target_attr=target_attr)
#Load (import) the shader networks from custom file(data) import pymel.core as pm import json import pprint import os #Read custom shader network data #write data filePath = os.path.join(os.environ['temp'], 'myTestShader.shader') shaderData = open(filePath, 'r') shaderNetworkData = json.load(shaderData) shaderData.close() #pprint.pprint(shaderNetworkData) shaderList = pm.listNodeTypes('shader') textureList = pm.listNodeTypes('texture') utilityList = pm.listNodeTypes('utility') for eachShaderNetwork in shaderNetworkData: #print eachShaderNetwork nodes = shaderNetworkData[eachShaderNetwork]['nodes'] attributes = shaderNetworkData[eachShaderNetwork]['attributes'] connections = shaderNetworkData[eachShaderNetwork]['connections'] geometries = shaderNetworkData[eachShaderNetwork]['geometries'] updateNode = {} #create nodes for eachNode in nodes: nodeType = nodes[eachNode]
def getLights(): return ( lgt for lgt in pym.ls(type=pym.listNodeTypes("light")) if lgt.type() in pym.nodeType("shape", derived=True, isTypeName=True))