本文整理匯總了Python中maya.cmds.namespace方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.namespace方法的具體用法?Python cmds.namespace怎麽用?Python cmds.namespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.namespace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: shapeSizeSetup
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def shapeSizeSetup(self, transformNode, *args):
""" Find shapes, create a cluster deformer to all and set the pivot to transform pivot.
Returns the created cluster.
"""
clusterHandle = None
childShapeList = cmds.listRelatives(transformNode, shapes=True, children=True)
# print "Child length {0}".format(len(childShapeList))
if childShapeList:
thisNamespace = childShapeList[0].split(":")[0]
cmds.namespace(set=thisNamespace, force=True)
clusterName = transformNode.split(":")[1]+"_ShapeSizeCH"
clusterHandle = cmds.cluster(childShapeList, name=clusterName)[1]
cmds.setAttr(clusterHandle+".visibility", 0)
cmds.xform(clusterHandle, scalePivot=(0, 0, 0), worldSpace=True)
cmds.namespace(set=":")
else:
print "There are not children shape to create shapeSize setup of:", transformNode
return clusterHandle
示例2: _nativeModel
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def _nativeModel(self):
"""
\remarks looks up the native model for this object
\sa model, setModel, _setNativeModel
\return <variant> nativeObject || None
"""
parent = self.parent()
while parent is not None:
if isinstance(parent, api.SceneModel):
return parent.nativePointer()
parent = parent.parent()
# namespace = self._namespace(self._nativePointer)['namespace']
# if namespace:
# return self._scene._findNativeObject(name=namespace)
return None
示例3: name
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def name(self, namespace=False):
"""Return the name of this node
Arguments:
namespace (bool, optional): Return with namespace,
defaults to False
Example:
>>> node = createNode("transform", name="myName")
>>> node.name()
u'myName'
"""
if namespace:
return self._fn.name()
else:
return self._fn.name().rsplit(":", 1)[-1]
示例4: remove
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def remove(container):
"""Remove an existing `container` from Maya scene
Deprecated; this functionality is replaced by `api.remove()`
Arguments:
container (avalon-core:container-1.0): Which container
to remove from scene.
"""
node = container["objectName"]
# Assume asset has been referenced
reference_node = next((node for node in cmds.sets(node, query=True)
if cmds.nodeType(node) == "reference"), None)
assert reference_node, ("Imported container not supported; "
"container must be referenced.")
log.info("Removing '%s' from Maya.." % container["name"])
namespace = cmds.referenceQuery(reference_node, namespace=True)
fname = cmds.referenceQuery(reference_node, filename=True)
cmds.file(fname, removeReference=True)
try:
cmds.delete(node)
except ValueError:
# Already implicitly deleted by Maya upon removing reference
pass
try:
# If container is not automatically cleaned up by May (issue #118)
cmds.namespace(removeNamespace=namespace, deleteNamespaceContent=True)
except RuntimeError:
pass
示例5: load
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def load(self,
context,
name=None,
namespace=None,
data=None):
return load(Loader=self.__class__,
representation=context['representation'],
name=name,
namespace=namespace,
data=data)
示例6: initGuide
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [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
示例7: __init__
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def __init__(self, dpUIinst, langDic, langName, presetDic, presetName, userGuideName, rigType, CLASS_NAME, TITLE, DESCRIPTION, ICON, *args):
""" Initialize the module class creating a button in createGuidesLayout in order to be used to start the guide module.
"""
# defining variables:
self.dpUIinst = dpUIinst
self.langDic = langDic
self.langName = langName
self.guideModuleName = CLASS_NAME
self.title = TITLE
self.description = DESCRIPTION
self.icon = ICON
self.userGuideName = userGuideName
self.rigType = rigType
self.presetDic = presetDic
self.presetName = presetName
self.ctrls = dpControls.ControlClass(self.dpUIinst, self.presetDic, self.presetName)
# defining namespace:
self.guideNamespace = self.guideModuleName + "__" + self.userGuideName
# defining guideNamespace:
cmds.namespace(setNamespace=":")
self.namespaceExists = cmds.namespace(exists=self.guideNamespace)
self.guideName = self.guideNamespace + ":Guide"
self.moduleGrp = self.guideName+"_Base"
self.radiusCtrl = self.moduleGrp+"_RadiusCtrl"
self.annotation = self.moduleGrp+"_Ant"
if not self.namespaceExists:
cmds.namespace(add=self.guideNamespace)
# create GUIDE for this module:
self.createGuide()
# create the Module layout in the mainUI - modulesLayoutA:
self.createModuleLayout()
# update module instance info:
self.updateModuleInstanceInfo()
示例8: deleteModule
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [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)
示例9: displayName
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def displayName(self):
# Ignore the name of the object, we only care about the namespace for tools.
return self._namespace(self._nativeTransform).get('namespace', '')
示例10: setDisplayName
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [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)
示例11: _createNativeModel
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [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
示例12: _nativeObjects
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def _nativeObjects(self, getsFromSelection=False, wildcard='', objectType=0):
""" Implements the AbstractScene._nativeObjects method to return the native objects from the scene
:return: list [<Py3dsMax.mxs.Object> nativeObject, ..]
"""
expression = cross3d.application._wildcardToRegex(wildcard)
regex = re.compile(expression, flags=re.I)
if getsFromSelection:
objects = self._selectionIter()
else:
# TODO MIKE: I had to support kCharacters aka key set cause they are part of what we export.
# The problem is not the export because we don't have to select them since they are "dependant".
# The issue is for when I try to re-apply the namespace after export.
mType = cross3d.SceneObject._abstractToNativeObjectType.get(objectType, (om.MFn.kDagNode, om.MFn.kCharacter))
objects = self._objectsOfMTypeIter(mType)
if objectType != 0 or wildcard:
container = []
for obj in objects:
typeCheck = True if not objectType else cross3d.SceneObject._typeOfNativeObject(obj) == objectType
wildcardCheck = True if not wildcard else regex.match(cross3d.SceneObject._mObjName(obj, False))
if typeCheck and wildcardCheck:
container.append(obj)
objects = container
return objects
示例13: namespace
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def namespace(self):
# I am not re-using the name method on purpose.
name = self._mObjName(self._nativeTransform, False)
# Splitting the name to detect for name spaces.
split = name.split(':')[0:]
if len(split) > 1:
return ':'.join(split[:-1])
return ''
示例14: setNamespace
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def setNamespace(self, namespace):
# I am not re-using the name method on purpose.
name = self._mObjName(self._nativeTransform, False)
displayName = name.split(':')[-1]
if not namespace:
cmds.rename(self.path(), self.displayName())
else:
if not cmds.namespace(exists=namespace):
cmds.namespace(add=namespace)
cmds.rename(self.path(), ':'.join([namespace, displayName]))
return True
示例15: _namespace
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import namespace [as 別名]
def _namespace(self, mObj):
name = self._mObjName(mObj, False)
return re.match(r'((?P<namespace>[^:]+):)?(?P<name>.+)', name).groupdict()