Python maya.cmds.namespaceInfo() Examples
The following are 11
code examples of maya.cmds.namespaceInfo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: shortcuts.py From cmt with MIT License | 6 votes |
def get_node_in_namespace_hierarchy(node, namespace=None, shape=False): """Searches a namespace and all nested namespaces for the given node. :param node: Name of the node. :param namespace: Root namespace :param shape: True to get the shape node, False to get the transform. :return: The node in the proper namespace. """ if shape and node and cmds.objExists(node): node = get_shape(node) if node and cmds.objExists(node): return node if node and namespace: # See if it exists in the namespace or any child namespaces namespaces = [namespace.replace(":", "")] namespaces += cmds.namespaceInfo(namespace, r=True, lon=True) or [] for namespace in namespaces: namespaced_node = "{0}:{1}".format(namespace, node) if shape: namespaced_node = get_shape(namespaced_node) if namespaced_node and cmds.objExists(namespaced_node): return namespaced_node return None
Example #2
Source File: lib.py From core with MIT License | 5 votes |
def unique_namespace(namespace, format="%02d", prefix="", suffix=""): """Return unique namespace Similar to :func:`unique_name` but evaluating namespaces as opposed to object names. Arguments: namespace (str): Name of namespace to consider format (str, optional): Formatting of the given iteration number suffix (str, optional): Only consider namespaces with this suffix. """ iteration = 1 unique = prefix + (namespace + format % iteration) + suffix # The `existing` set does not just contain the namespaces but *all* nodes # within "current namespace". We need all because the namespace could # also clash with a node name. To be truly unique and valid one needs to # check against all. existing = set(cmds.namespaceInfo(listNamespace=True)) while unique in existing: iteration += 1 unique = prefix + (namespace + format % iteration) + suffix return unique
Example #3
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def initGuide(self, guideModule, guideDir, rigType=Base.RigType.biped, *args): """ Create a guideModuleReference (instance) of a further guideModule that will be rigged (installed). Returns the guide instance initialised. """ # creating unique namespace: cmds.namespace(setNamespace=":") # list all namespaces: namespaceList = cmds.namespaceInfo(listOnlyNamespaces=True) # check if there is "__" (double undersore) in the namespaces: for i in range(len(namespaceList)): if namespaceList[i].find("__") != -1: # if yes, get the name after the "__": namespaceList[i] = namespaceList[i].partition("__")[2] # send this result to findLastNumber in order to get the next moduleName +1: newSuffix = utils.findLastNumber(namespaceList, BASE_NAME) + 1 # generate the current moduleName added the next new suffix: userSpecName = BASE_NAME + str(newSuffix) # especific import command for guides storing theses guides modules in a variable: basePath = utils.findEnv("PYTHONPATH", "dpAutoRigSystem") self.guide = __import__(basePath+"."+guideDir+"."+guideModule, {}, {}, [guideModule]) reload(self.guide) # get the CLASS_NAME from guideModule: guideClass = getattr(self.guide, self.guide.CLASS_NAME) # initialize this guideModule as an guide Instance: guideInstance = guideClass(self, self.langDic, self.langName, self.presetDic, self.presetName, userSpecName, rigType) self.moduleInstancesList.append(guideInstance) # edit the footer A text: self.allGuidesList.append([guideModule, userSpecName]) self.modulesToBeRiggedList = utils.getModulesToBeRigged(self.moduleInstancesList) cmds.text(self.allUIs["footerAText"], edit=True, label=str(len(self.modulesToBeRiggedList)) +" "+ self.langDic[self.langName]['i005_footerA']) return guideInstance
Example #4
Source File: dpBaseClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def deleteModule(self, *args): """ Delete the Guide, ModuleLayout and Namespace. """ # delete mirror preview: try: cmds.delete(self.moduleGrp[:self.moduleGrp.find(":")]+"_MirrorGrp") except: pass # delete the guide module: utils.clearNodeGrp(nodeGrpName=self.moduleGrp, attrFind='guideBase', unparent=True) # clear default 'dpAR_GuideMirror_Grp': utils.clearNodeGrp() # remove the namespaces: allNamespaceList = cmds.namespaceInfo(listOnlyNamespaces=True) if self.guideNamespace in allNamespaceList: cmds.namespace(moveNamespace=(self.guideNamespace, ':'), force=True) cmds.namespace(removeNamespace=self.guideNamespace, force=True) try: # delete the moduleFrameLayout from window UI: cmds.deleteUI(self.moduleFrameLayout) self.clearSelectedModuleLayout() # edit the footer A text: self.currentText = cmds.text("footerAText", query=True, label=True) cmds.text("footerAText", edit=True, label=str(int(self.currentText[:self.currentText.find(" ")]) - 1) +" "+ self.langDic[self.langName]['i005_footerA']) except: pass # clear module from instance list (clean dpUI list): delIndex = self.dpUIinst.moduleInstancesList.index(self) self.dpUIinst.moduleInstancesList.pop(delIndex)
Example #5
Source File: dpUtils.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def getModulesToBeRigged(instanceList): """ Get all valid loaded modules to be rigged (They are valid instances with namespaces in the scene, then they are not deleted). Return a list of modules to be rigged. """ modulesToBeRiggedList = [] allNamespaceList = cmds.namespaceInfo(listNamespace=True) for guideModule in instanceList: # verify integrity of the guideModule: if guideModule.verifyGuideModuleIntegrity(): guideNamespaceName = guideModule.guideNamespace if guideNamespaceName in allNamespaceList: userGuideName = guideModule.userGuideName if not cmds.objExists(userGuideName+'_Grp'): modulesToBeRiggedList.append(guideModule) return modulesToBeRiggedList
Example #6
Source File: mayascenemodel.py From cross3d with MIT License | 5 votes |
def setDisplayName(self, name): name = name.replace('-', '_') # If the model using a namespace, rename the namespace not the object. namespace = self._namespace(self._nativeTransform)['namespace'] if namespace: if namespace == name: # Renaming the model to its current name, nothing to do. return # TODO: pull the reference node from the namespace instead of storing it in a user prop # that way if a user swaps reference in the Reference Editor we won't loose track of it. filename = self.resolutionPath(self.resolution()) if self.isReferenced() and filename: cmds.file(filename, edit=True, namespace=name, mergeNamespacesOnClash=True) # Doc's say cmds.file should move non-referenced nodes to the new namespace, but # in practice it doesn't. If the old namespace still exists, move all of its # nodes into the new namespace and remove the old namespace if namespace in cmds.namespaceInfo(listOnlyNamespaces=True): cmds.namespace(moveNamespace=[namespace, name]) cmds.namespace(removeNamespace=namespace) else: namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) if name in namespaces: # If the namespace already exists we need to auto-increment the value or the # rename command will error out # reverse the name and pull off any trailing digits revName = re.match('(?P<revIter>\d*)(?P<name>.+)', name[::-1]) if revName: n = revName.group('name')[::-1] v = int(revName.group('revIter')[::-1] or 1) while '{name}{revIter}'.format(name=n, revIter=v) in namespaces: v += 1 name = '{name}{revIter}'.format(name=n, revIter=v) else: name = '{name}1'.format(name=name) cmds.namespace(rename=[namespace, name]) return super(MayaSceneModel, self).setDisplayName(name)
Example #7
Source File: mayascene.py From cross3d with MIT License | 5 votes |
def _createNativeModel(self, name='Model', nativeObjects=[], referenced=False): name = 'Model' if not name else name # Create a "model" namespace and add the locator to it # TODO: Make this a context currentNamespace = cmds.namespaceInfo(currentNamespace=True) namespace = cmds.namespace(addNamespace=name) cmds.namespace(setNamespace=namespace) # Create the transform node then the shape node so the transform is properly named parent = cmds.createNode('transform', name='Model') #name = cmds.createNode('locator', name='{}Shape'.format(name), parent=parent) output = cross3d.SceneWrapper._asMOBject(parent) userProps = cross3d.UserProps(output) userProps['model'] = True if referenced: userProps['referenced'] = referenced # Create the Active_Resolution enum if it doesn't exist # cmds.addAttr(name, longName="Active_Resolution", attributeType="enum", enumName="Offloaded:") # userProps['Resolutions'] = OrderedDict(Offloaded='') cmds.namespace(setNamespace=currentNamespace) # Add each of nativeObjects to the model namespace if nativeObjects: for nativeObject in nativeObjects: nativeObject = cross3d.SceneWrapper._getTransformNode(nativeObject) objName = cross3d.SceneWrapper._mObjName(nativeObject) # cmds.parent(objName, cross3d.SceneWrapper._mObjName(nativeParent)) nameInfo = cross3d.SceneWrapper._namespace(nativeObject) newName = '{namespace}:{name}'.format(namespace=namespace, name=nameInfo['name']) cmds.rename(objName, newName) nativeObjects.append(output) return output
Example #8
Source File: publish.py From anima with MIT License | 5 votes |
def delete_empty_namespaces(progress_controller=None): """Delete empty namespaces checks and deletes empty namespaces """ if progress_controller is None: progress_controller = ProgressControllerBase() # only allow namespaces with DAG objects in it and no child namespaces empty_namespaces = [] all_namespaces = mc.namespaceInfo( recurse=True, listOnlyNamespaces=True, internal=False ) or [] progress_controller.maximum = len(all_namespaces) for ns in all_namespaces: if ns not in ['UI', 'shared']: child_namespaces = mc.namespaceInfo(ns, listNamespace=True) if not child_namespaces and len( mc.ls(mc.namespaceInfo(ns, listOnlyDependencyNodes=True), dag=True, mat=True)) == 0: empty_namespaces.append(ns) progress_controller.increment() for ns in empty_namespaces: mc.namespace(rm=ns, mnr=True) progress_controller.complete()
Example #9
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 4 votes |
def populateCreatedGuideModules(self, *args): """ Read all guide modules loaded in the scene and re-create the elements in the moduleLayout. """ # create a new list in order to store all created guide modules in the scene and its userSpecNames: self.allGuidesList = [] self.moduleInstancesList = [] # list all namespaces: cmds.namespace(setNamespace=":") namespaceList = cmds.namespaceInfo(listOnlyNamespaces=True) # find path where 'dpAutoRig.py' is been executed: path = utils.findPath("dpAutoRig.py") guideDir = MODULES # find all module names: moduleNameInfo = utils.findAllModuleNames(path, guideDir) validModules = moduleNameInfo[0] validModuleNames = moduleNameInfo[1] # check if there is "__" (double undersore) in the namespaces: for n in namespaceList: divString = n.partition("__") if divString[1] != "": module = divString[0] userSpecName = divString[2] if module in validModuleNames: index = validModuleNames.index(module) # check if there is this module guide base in the scene: curGuideName = validModuleNames[index]+"__"+userSpecName+":"+GUIDE_BASE_NAME if cmds.objExists(curGuideName): self.allGuidesList.append([validModules[index], userSpecName, curGuideName]) # if exists any guide module in the scene, recreate its instance as objectClass: if self.allGuidesList: # clear current layout before reload modules: cmds.deleteUI(self.allUIs["modulesLayoutA"]) self.allUIs["modulesLayoutA"] = cmds.columnLayout("modulesLayoutA", adjustableColumn=True, width=200, parent=self.allUIs["colMiddleRightA"]) # load again the modules: guideFolder = utils.findEnv("PYTHONPATH", "dpAutoRigSystem")+"."+MODULES # this list will be used to rig all modules pressing the RIG button: for module in self.allGuidesList: mod = __import__(guideFolder+"."+module[0], {}, {}, [module[0]]) reload(mod) # identify the guide modules and add to the moduleInstancesList: moduleClass = getattr(mod, mod.CLASS_NAME) dpUIinst = self if cmds.attributeQuery("rigType", node=module[2], ex=True): curRigType = cmds.getAttr(module[2] + ".rigType") moduleInst = moduleClass(dpUIinst, self.langDic, self.langName, self.presetDic, self.presetName, module[1], curRigType) else: if cmds.attributeQuery("Style", node=module[2], ex=True): iStyle = cmds.getAttr(module[2] + ".Style") if (iStyle == 0 or iStyle == 1): moduleInst = moduleClass(dpUIinst, self.langDic, self.langName, self.presetDic, self.presetName, module[1], Base.RigType.biped) else: moduleInst = moduleClass(dpUIinst, self.langDic, self.langName, self.presetDic, self.presetName, module[1], Base.RigType.quadruped) else: moduleInst = moduleClass(dpUIinst, self.langDic, self.langName, self.presetDic, self.presetName, module[1], Base.RigType.default) self.moduleInstancesList.append(moduleInst) # edit the footer A text: self.modulesToBeRiggedList = utils.getModulesToBeRigged(self.moduleInstancesList) cmds.text(self.allUIs["footerAText"], edit=True, label=str(len(self.modulesToBeRiggedList)) +" "+ self.langDic[self.langName]['i005_footerA'])
Example #10
Source File: maya_warpper.py From pipeline with MIT License | 4 votes |
def clean_up_file(): pass # import references """ refs = cmds.ls(type='reference') for i in refs: rFile = cmds.referenceQuery(i, f=True) cmds.file(rFile, importReference=True, mnr=True) defaults = ['UI', 'shared'] # Used as a sort key, this will sort namespaces by how many children they have. def num_children(ns): return ns.count(':') namespaces = [ns for ns in cmds.namespaceInfo(lon=True, r=True) if ns not in defaults] # We want to reverse the list, so that namespaces with more children are at the front of the list. namespaces.sort(key=num_children, reverse=True) for ns in namespaces: if namespaces.index(ns)+1 < len(namespaces): parent_ns = namespaces[namespaces.index(ns)+1] cmds.namespace(mv=[ns,parent_ns], f=True) cmds.namespace(rm=ns) else: cmds.namespace(mv=[ns,":"], f=True) cmds.namespace(rm=ns) # remove ngSkinTools custom nodes from ngSkinTools.layerUtils import LayerUtils LayerUtils.deleteCustomNodes() # remove RRM proxies if cmds.objExists("RRM_MAIN"): cmds.select("RRM_MAIN",hi=True) proxies = cmds.ls(sl=True) cmds.lockNode(proxies,lock=False) cmds.delete(proxies) if cmds.objExists("RRM_ProxiesLayer"): cmds.delete("RRM_ProxiesLayer")"""
Example #11
Source File: mayascenemodel.py From cross3d with MIT License | 4 votes |
def export(self, fileName): name = self.name() objects = self.objects() selection = self._scene.selection() # Selecting the object. self._scene.setSelection(objects) # Make sure we set the current namespace to root otherwise the next line does not work. initialNamespace = cmds.namespaceInfo(currentNamespace=True) cmds.namespace(setNamespace=":" ) # Trashing the namespace. cmds.namespace(removeNamespace=name, mergeNamespaceWithRoot=True) # Remove attributes that should not be stored in a exported model. userProps = self.userProps() resolutions = None resolution = {} if 'resolutions' in userProps: resolutions = userProps.pop('resolutions') if resolutionAttr in userProps: # Resolution is a bit complicated because it can be a enum. if cmds.attributeQuery(resolutionAttr, node= self._nativeName(), attributeType=True) == 'enum': # Store the enum list resolution['names'] = cmds.attributeQuery( resolutionAttr, node=self._nativeName(), listEnum=True) resolution['value'] = self.userProps().pop(resolutionAttr) # Export the model cmds.file(fileName, force=True, exportSelected=True, typ="mayaAscii", usingNamespaces=False) # Restore the attributes we used earlier userProps = self.userProps() if resolutions != None: userProps['resolutions'] = resolutions if resolution: if 'names' in resolution: cmds.addAttr(self._nativeName(), longName=resolutionAttr, attributeType="enum", enumName=resolution['names'][0]) cmds.setAttr(self._attrName(), keyable=False, channelBox=True) cmds.setAttr(self._attrName(), resolution['value']) else: userProps[resolutionAttr] = resolution['value'] # Re-add all items to the namespace for obj in objects: # TODO: Optomize setNamespace, it checks for if the namespace exists before renameing. # In this case this is unneccissary. obj.setNamespace(name) # Restoring the namespace. cmds.namespace(setNamespace=initialNamespace) # Restoring selection self._scene.setSelection(selection) return True