當前位置: 首頁>>代碼示例>>Python>>正文


Python cmds.namespaceInfo方法代碼示例

本文整理匯總了Python中maya.cmds.namespaceInfo方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.namespaceInfo方法的具體用法?Python cmds.namespaceInfo怎麽用?Python cmds.namespaceInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maya.cmds的用法示例。


在下文中一共展示了cmds.namespaceInfo方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_node_in_namespace_hierarchy

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:chadmv,項目名稱:cmt,代碼行數:27,代碼來源:shortcuts.py

示例2: unique_namespace

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:getavalon,項目名稱:core,代碼行數:28,代碼來源:lib.py

示例3: initGuide

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:33,代碼來源:dpAutoRig.py

示例4: deleteModule

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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) 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:31,代碼來源:dpBaseClass.py

示例5: getModulesToBeRigged

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:17,代碼來源:dpUtils.py

示例6: setDisplayName

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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) 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:41,代碼來源:mayascenemodel.py

示例7: _createNativeModel

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:33,代碼來源:mayascene.py

示例8: delete_empty_namespaces

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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() 
開發者ID:eoyilmaz,項目名稱:anima,代碼行數:32,代碼來源:publish.py

示例9: populateCreatedGuideModules

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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']) 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:62,代碼來源:dpAutoRig.py

示例10: clean_up_file

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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")""" 
開發者ID:liorbenhorin,項目名稱:pipeline,代碼行數:44,代碼來源:maya_warpper.py

示例11: export

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespaceInfo [as 別名]
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 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:56,代碼來源:mayascenemodel.py


注:本文中的maya.cmds.namespaceInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。