无法重命名 Maya 锁定节点

Can't rename a Maya locked node

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. //

如何改进我的代码以重命名锁定的节点?[​​=12=]

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为可选参数,默认值为
  • 此代码将解锁节点但不会在重命名后锁定它们
  • 我没有重命名形状,因为重命名变换会自动重命名形状。