本文整理汇总了Python中maya.cmds.rename方法的典型用法代码示例。如果您正苦于以下问题:Python cmds.rename方法的具体用法?Python cmds.rename怎么用?Python cmds.rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.cmds
的用法示例。
在下文中一共展示了cmds.rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: renameShape
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def renameShape(self, transformList, *args):
"""Find shapes, rename them to Shapes and return the results.
"""
resultList = []
for transform in transformList:
# list all children shapes:
childShapeList = cmds.listRelatives(transform, shapes=True, children=True, fullPath=True)
if childShapeList:
# verify if there is only one shape and return it renamed:
if len(childShapeList) == 1:
shape = cmds.rename(childShapeList[0], transform+"Shape")
cmds.select(clear=True)
resultList.append(shape)
# else rename and return one list of renamed shapes:
elif len(childShapeList) > 1:
for i, child in enumerate(childShapeList):
shape = cmds.rename(child, transform+str(i)+"Shape")
resultList.append(shape)
cmds.select(clear=True)
else:
print "There are not children shape to rename inside of:", transform
return resultList
示例2: createCurveShape
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def createCurveShape(name, points):
"""
Create a curve and rename the shapes to be unique.
:param str name: Name of curve
:param list points: List of points.
"""
# create curve
curve = cmds.curve(p=points, d=1, n=name)
# rename shapes
shapes = []
for shape in cmds.listRelatives(curve, s=True, f=True) or []:
shape = cmds.rename(shape, "{0}Shape".format(name))
shapes.append(shape)
return curve, shapes
示例3: name_changed
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def name_changed(self, widget, name):
""" triggered by one of the spore widgets when the user
requests a name change
:param widget: the source of the signal
:param name: the new name """
node_name = widget.long_name
if cmds.objExists(node_name):
if re.match('^[A-Za-z0-9_-]*$', name) and not name[0].isdigit():
# transform = cmds.listRelatives(node_name, p=True, f=True)[0]
instancer = node_utils.get_instancer(node_name)
cmds.rename(instancer, '{}Instancer'.format(name))
cmds.rename(node_name, '{}Shape'.format(name))
# cmds.rename(transform, name)
else:
self.io.set_message('Invalid Name: Use only A-Z, a-z, 0-9, -, _', 2)
return
self.refresh_spore()
示例4: maya_import
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def maya_import():
temp = __name__.split('.')#nameは自分自身のモジュール名。splitでピリオドごとに3分割。
folderPath = os.path.join(os.getenv('MAYA_APP_DIR'),'Scripting_Files','go')
if not os.path.exists(folderPath):
os.makedirs(os.path.dirname(folderPath+'\\')) # 末尾\\が必要なので注意
#print folderPath
files = os.listdir(folderPath)
if files is not None:
for file in files:
print file
nameSpace = file.replace('.ma', '')
cmds.file(folderPath+'\\'+file, i=True, typ="mayaAscii", iv=True, mnc=False, options="v=0;", pr=True)
#重複マテリアルにファイル名が頭に付与されてしまうのを修正
allMat = cmds.ls(mat=True)
fileName = file.split('.')[0]
for mat in allMat:
if mat.startswith(fileName+'_'):
cmds.rename(mat, mat.replace(fileName+'_', ''))
cmds.inViewMessage( amg='<hl>Go Maya</hl> : Imoprt objects', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
else:
cmds.inViewMessage( amg='<hl>Go Maya</hl> : There is no exported object', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
示例5: _createNativeCamera
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def _createNativeCamera(self, name='Camera', type='Standard', target=None, rotationOrder=None):
""" Implements the AbstractScene._createNativeCamera method to return a new Studiomax camera
:param name: <str>
:return: <variant> nativeCamera || None
"""
if type == 'V-Ray':
cross3d.logger.debug('V-Ray cameras are not supported currently')
return None
else:
if target != None:
cross3d.logger.debug('Target not supported currently.')
tform, shape = cmds.camera()
# Set the rotation order for the camera.
if rotationOrder == None:
rotationOrder = cross3d.SceneCamera.defaultRotationOrder()
cross3d.SceneObject._setNativeRotationOrder(tform, rotationOrder)
nativeCamera = cross3d.SceneWrapper._asMOBject(shape)
cmds.rename(tform, name)
return nativeCamera
示例6: convertSkelSettingsToNN
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def convertSkelSettingsToNN(delete=1):
orig = 'SkeletonSettings_Cache'
if cmds.objExists(orig):
if cmds.nodeType(orig) == 'unknown':
new = cmds.createNode('network')
for att in cmds.listAttr(orig):
if not cmds.attributeQuery(att, node=new, exists=1):
typ = cmds.attributeQuery(att, node=orig, at=1)
if typ == 'typed':
cmds.addAttr(new, longName=att, dt='string')
if cmds.getAttr(orig + '.' + att):
cmds.setAttr(new + '.' + att, cmds.getAttr(orig + '.' + att), type='string')
elif typ == 'enum':
cmds.addAttr(new, longName=att, at='enum', enumName=cmds.attributeQuery(att, node=orig, listEnum=1)[0])
cmds.delete(orig)
cmds.rename(new, 'SkeletonSettings_Cache')
示例7: orient_to_world
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def orient_to_world(joints):
"""Orients the given joints with the world.
@param joints: Joints to orient.
"""
for joint in joints:
children = _unparent_children(joint)
parent = cmds.listRelatives(joint, parent=True, path=True)
orig_joint = joint.split("|")[-1]
if parent:
joint = cmds.parent(joint, world=True)[0]
cmds.joint(joint, e=True, oj="none", zso=True)
if parent:
joint = cmds.parent(joint, parent)[0]
joint = cmds.rename(joint, orig_joint)
_reparent_children(joint, children)
if joints:
cmds.select(joints)
示例8: import_obj
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def import_obj(file_path):
old_nodes = set(cmds.ls(assemblies=True))
cmds.file(
file_path,
i=True,
type="OBJ",
ignoreVersion=True,
mergeNamespacesOnClash=False,
options="mo=0",
)
new_nodes = set(cmds.ls(assemblies=True))
new_nodes = new_nodes.difference(old_nodes)
new_mesh = list(new_nodes)[0]
name = os.path.splitext(os.path.basename(file_path))[0]
return cmds.rename(new_mesh, name)
示例9: maya_import
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def maya_import():
temp = __name__.split('.')#nameは自分自身のモジュール名。splitでピリオドごとに3分割。
folderPath = os.path.join(os.getenv('MAYA_APP_DIR'),'Scripting_Files','go')
if not os.path.exists(folderPath):
os.makedirs(os.path.dirname(folderPath+os.sep)) # 末尾\\が必要なので注意
#print folderPath
files = os.listdir(folderPath)
if files is not None:
for file in files:
print file
nameSpace = file.replace('.ma', '')
cmds.file(folderPath+os.sep+file, i=True, typ="mayaAscii", iv=True, mnc=False, options="v=0;", pr=True)
#重複マテリアルにファイル名が頭に付与されてしまうのを修正
allMat = cmds.ls(mat=True)
fileName = file.split('.')[0]
for mat in allMat:
if mat.startswith(fileName+'_'):
cmds.rename(mat, mat.replace(fileName+'_', ''))
cmds.inViewMessage( amg='<hl>Go Maya</hl> : Imoprt objects', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
else:
cmds.inViewMessage( amg='<hl>Go Maya</hl> : There is no exported object', pos='midCenterTop', fade=True, ta=0.75, a=0.5)
示例10: cvJointLoc
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def cvJointLoc(self, ctrlName, r=0.3, d=1, rot=(0, 0, 0), guide=True, *args):
"""Create and return a cvJointLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize.
"""
# create locator curve:
cvLoc = self.cvLocator(ctrlName+"_CvLoc", r, d)
# create arrow curves:
cvArrow1 = cmds.curve(n=ctrlName+"_CvArrow1", d=3, p=[(-0.1*r, 0.9*r, 0.2*r), (-0.1*r, 0.9*r, 0.23*r), (-0.1*r, 0.9*r, 0.27*r), (-0.1*r, 0.9*r, 0.29*r), (-0.1*r, 0.9*r, 0.3*r), (-0.372*r, 0.9*r, 0.24*r), (-0.45*r, 0.9*r, -0.13*r), (-0.18*r, 0.9*r, -0.345*r), (-0.17*r, 0.9*r, -0.31*r), (-0.26*r, 0.9*r, -0.41*r), (-0.21*r, 0.9*r, -0.41*r), (-0.05*r, 0.9*r, -0.4*r), (0, 0.9*r, -0.4*r), (-0.029*r, 0.9*r, -0.33*r), (-0.048*r, 0.9*r, -0.22*r), (-0.055*r, 0.9*r, -0.16*r), (-0.15*r, 0.9*r, -0.272*r), (-0.12*r, 0.9*r, -0.27*r), (-0.35*r, 0.9*r, -0.1*r), (-0.29*r, 0.9*r, 0.15*r), (-0.16*r, 0.9*r, 0.21*r), (-0.1*r, 0.9*r, 0.2*r)] )
cvArrow2 = cmds.curve(n=ctrlName+"_CvArrow2", d=3, p=[(0.1*r, 0.9*r, -0.2*r), (0.1*r, 0.9*r, -0.23*r), (0.1*r, 0.9*r, -0.27*r), (0.1*r, 0.9*r, -0.29*r), (0.1*r, 0.9*r, -0.3*r), (0.372*r, 0.9*r, -0.24*r), (0.45*r, 0.9*r, 0.13*r), (0.18*r, 0.9*r, 0.345*r), (0.17*r, 0.9*r, 0.31*r), (0.26*r, 0.9*r, 0.41*r), (0.21*r, 0.9*r, 0.41*r), (0.05*r, 0.9*r, 0.4*r), (0, 0.9*r, 0.4*r), (0.029*r, 0.9*r, 0.33*r), (0.048*r, 0.9*r, 0.22*r), (0.055*r, 0.9*r, 0.16*r), (0.15*r, 0.9*r, 0.272*r), (0.12*r, 0.9*r, 0.27*r), (0.35*r, 0.9*r, 0.1*r), (0.29*r, 0.9*r, -0.15*r), (0.16*r, 0.9*r, -0.21*r), (0.1*r, 0.9*r, -0.2*r)] )
cvArrow3 = cmds.curve(n=ctrlName+"_CvArrow3", d=3, p=[(-0.1*r, -0.9*r, 0.2*r), (-0.1*r, -0.9*r, 0.23*r), (-0.1*r, -0.9*r, 0.27*r), (-0.1*r, -0.9*r, 0.29*r), (-0.1*r, -0.9*r, 0.3*r), (-0.372*r, -0.9*r, 0.24*r), (-0.45*r, -0.9*r, -0.13*r), (-0.18*r, -0.9*r, -0.345*r), (-0.17*r, -0.9*r, -0.31*r), (-0.26*r, -0.9*r, -0.41*r), (-0.21*r, -0.9*r, -0.41*r), (-0.05*r, -0.9*r, -0.4*r), (0, -0.9*r, -0.4*r), (-0.029*r, -0.9*r, -0.33*r), (-0.048*r, -0.9*r, -0.22*r), (-0.055*r, -0.9*r, -0.16*r), (-0.15*r, -0.9*r, -0.272*r), (-0.12*r, -0.9*r, -0.27*r), (-0.35*r, -0.9*r, -0.1*r), (-0.29*r, -0.9*r, 0.15*r), (-0.16*r, -0.9*r, 0.21*r), (-0.1*r, -0.9*r, 0.2*r)] )
cvArrow4 = cmds.curve(n=ctrlName+"_CvArrow4", d=3, p=[(0.1*r, -0.9*r, -0.2*r), (0.1*r, -0.9*r, -0.23*r), (0.1*r, -0.9*r, -0.27*r), (0.1*r, -0.9*r, -0.29*r), (0.1*r, -0.9*r, -0.3*r), (0.372*r, -0.9*r, -0.24*r), (0.45*r, -0.9*r, 0.13*r), (0.18*r, -0.9*r, 0.345*r), (0.17*r, -0.9*r, 0.31*r), (0.26*r, -0.9*r, 0.41*r), (0.21*r, -0.9*r, 0.41*r), (0.05*r, -0.9*r, 0.4*r), (0, -0.9*r, 0.4*r), (0.029*r, -0.9*r, 0.33*r), (0.048*r, -0.9*r, 0.22*r), (0.055*r, -0.9*r, 0.16*r), (0.15*r, -0.9*r, 0.272*r), (0.12*r, -0.9*r, 0.27*r), (0.35*r, -0.9*r, 0.1*r), (0.29*r, -0.9*r, -0.15*r), (0.16*r, -0.9*r, -0.21*r), (0.1*r, -0.9*r, -0.2*r)] )
cvArrow5 = cmds.curve(n=ctrlName+"_CvArrow5", d=1, p=[(0, 0, 1.2*r), (0.09*r, 0, 1*r), (-0.09*r, 0, 1*r), (0, 0, 1.2*r)] )
cvArrow6 = cmds.curve(n=ctrlName+"_CvArrow6", d=1, p=[(0, 0, 1.2*r), (0, 0.09*r, 1*r), (0, -0.09*r, 1*r), (0, 0, 1.2*r)] )
# rename curveShape:
locArrowList = [cvLoc, cvArrow1, cvArrow2, cvArrow3, cvArrow4, cvArrow5, cvArrow6]
self.renameShape(locArrowList)
# create ball curve:
cvTemplateBall = self.cvControl("Ball", ctrlName+"_CvBall", r=0.7*r, d=3)
# parent shapes to transform:
locCtrl = cmds.group(name=ctrlName, empty=True)
ballChildrenList = cmds.listRelatives(cvTemplateBall, shapes=True, children=True)
for ballChildren in ballChildrenList:
cmds.setAttr(ballChildren+".template", 1)
self.transferShape(True, False, cvTemplateBall, [locCtrl])
for transform in locArrowList:
self.transferShape(True, False, transform, [locCtrl])
# set rotation direction:
cmds.setAttr(locCtrl+".rotateX", rot[0])
cmds.setAttr(locCtrl+".rotateY", rot[1])
cmds.setAttr(locCtrl+".rotateZ", rot[2])
cmds.makeIdentity(locCtrl, rotate=True, apply=True)
# create an attribute to be used as guide by module:
cmds.addAttr(locCtrl, longName="nJoint", attributeType='long')
cmds.setAttr(locCtrl+".nJoint", 1)
# colorize curveShapes:
self.colorShape([locCtrl], 'blue')
# shapeSize setup:
shapeSizeCluster = self.shapeSizeSetup(locCtrl)
cmds.select(clear=True)
return [locCtrl, shapeSizeCluster]
示例11: cvCharacter
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def cvCharacter(self, ctrlType, ctrlName, r=1, d=1, dir="+Y", rot=(0, 0, 0), *args):
""" Create and return a curve to be used as a control.
"""
# get radius by checking linear unit
r = self.dpCheckLinearUnit(r)
curve = self.cvControl(ctrlType, ctrlName, r, d, dir, rot)
# edit a minime curve:
cmds.addAttr(curve, longName="rigScale", attributeType='float', defaultValue=1, keyable=True)
cmds.addAttr(curve, longName="rigScaleMultiplier", attributeType='float', defaultValue=1, keyable=False)
# create Option_Ctrl Text:
try:
optCtrlTxt = cmds.group(name="Option_Ctrl_Txt", empty=True)
try:
cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Source Sans Pro", text="Option Ctrl", constructionHistory=False)[0]
except:
cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Arial", text="Option Ctrl", constructionHistory=False)[0]
txtShapeList = cmds.listRelatives(cvText, allDescendents=True, type='nurbsCurve')
if txtShapeList:
for s, shape in enumerate(txtShapeList):
# store CV world position
curveCVList = cmds.getAttr(shape+'.cp', multiIndices=True)
vtxWorldPosition = []
for i in curveCVList :
cvPointPosition = cmds.xform(shape+'.cp['+str(i)+']', query=True, translation=True, worldSpace=True)
vtxWorldPosition.append(cvPointPosition)
# parent the shapeNode :
cmds.parent(shape, optCtrlTxt, r=True, s=True)
# restore the shape world position
for i in curveCVList:
cmds.xform(shape+'.cp['+str(i)+']', a=True, worldSpace=True, t=vtxWorldPosition[i])
cmds.rename(shape, optCtrlTxt+"Shape"+str(s))
cmds.delete(cvText)
cmds.parent(optCtrlTxt, curve)
cmds.setAttr(optCtrlTxt+".template", 1)
cmds.setAttr(optCtrlTxt+".tx", -0.72*r)
cmds.setAttr(optCtrlTxt+".ty", 1.1*r)
except:
# it will pass if we don't able to find the font to create the text
pass
return curve
示例12: rename_textures
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def rename_textures(delUnuseTex=True):
attrPort = [ '.outColor', '.outAlpha', '.outTransparency' ]
textures = cmds.ls(tex=True)
#テクスチャを一括リネーム、未使用のものは削除
for tex in textures:
deleteFlag = True#削除フラグ
for portName in attrPort:
#接続されたノードを返す。pフラグでアトリビュート名を合わせて取得。
try:
connectItems = cmds.listConnections(tex+portName, p=True)
except:
print 'Get Attribute Error : '+texA+'.'+portName
continue
#接続を取得した変数がnoneTypeでなければ(接続があれば)
if connectItems is not None:
#if not isinstance(connectItems,type(None)):
deleteFlag = False#削除フラグをFalseに
if deleteFlag and delUnuseTex:#削除フラグがTrueなら
cmds.delete(tex)#テクスチャ削除
continue#以降のリネーム処理を行わずfor文の最初に戻る
try:
sourceName = cmds.getAttr(tex+'.fileTextureName')
fileExpName = sourceName.split('/')[-1]
fileExpName = fileExpName.split('\\')[-1]
fileName = fileExpName.split('.')[0]
cmds.rename(tex,fileName)
except:
print 'Rename Error : '+tex
continue
示例13: _createNativeModel
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [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
示例14: setNamespace
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [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: setNamespace
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import rename [as 别名]
def setNamespace(self, namespace):
# I am not re-using the name method on purpose.
name = self._mObjName(self._nativePointer, 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