import maya.cmds as cmds
def replace(char):
locators = cmds.ls(tr=True, s=True,type=('joint')) or []
try:
for lp in locators:
if char in lp:
newFilename = lp.replace(char, "a")
cmds.rename(lp, newFilename)
except:
print "yes"
charReplace="Ghoul"
charReplace2="SHJnt"
charReplace3="head"
charReplace4="spine"
charReplace5="arm"
charReplace6="leg"
replace(charReplace)
replace(charReplace2)
replace(charReplace3)
replace(charReplace4)
replace(charReplace5)
replace(charReplace6)
我正在尝试重命名Maya场景中的所有节点。
此当前代码仅重命名这些节点:Ghoul和SHJnt。
我无法重命名头节点。
尝试重命名时出现以下错误:
// Error: line 1: Cannot rename a locked node. //
如何改进我的代码才能重命名锁定的节点?
答案 0 :(得分:0)
import maya.cmds as cmds
########################################
# This function renames Maya nodes whose name contains oldString value
# newString is an optionnal argument
########################################
def renameNode(oldString, newString="a"):
# I don't really understand why you are passing these flags in the ls() function
# node_list = cmds.ls(tr=True, s=True,type=('joint'))
# I would recommand to only list nodes that might interest you using *
# * acts as a wildcard
node_list = cmds.ls( "*" + oldString + "*", tr=True )
# Iterate through each node in the list
for node in node_list:
# Now unlock the node entirely
# You can also check the doc for the flag lockName
cmds.lockNode(node, lock=False)
# Rename the node
cmds.rename( node, node.replace(oldString, newString) )
renameNode("Ghoul")
renameNode("SHJnt")
renameNode("head")
renameNode("spine")
renameNode("arm", "NewName")
renameNode("leg", "OtherName")
newString
是一个optionnal参数,它的默认值是