python - Can't rename a Maya locked node -
import maya.cmds cmds def replace(char): locators = cmds.ls(tr=true, s=true,type=('joint')) or [] try: 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) i'm trying rename nodes in maya scene.
this current code renames these nodes: ghoul , shjnt.
i can't rename head node.
i following error when try rename it: // error: line 1: cannot rename locked node. //
how can improve code able rename locked nodes?
import maya.cmds cmds ######################################## # function renames maya nodes name contains oldstring value # newstring optionnal argument ######################################## def renamenode(oldstring, newstring="a"): # don't understand why passing these flags in ls() function # node_list = cmds.ls(tr=true, s=true,type=('joint')) # recommand list nodes might interest using * # * acts wildcard node_list = cmds.ls( "*" + oldstring + "*", tr=true ) # iterate through each node in list node in node_list: # unlock node entirely # can check doc flag lockname cmds.locknode(node, lock=false) # rename node cmds.rename( node, node.replace(oldstring, newstring) ) renamenode("ghoul") renamenode("shjnt") renamenode("head") renamenode("spine") renamenode("arm", "newname") renamenode("leg", "othername") newstringoptionnal parameter, it's default value a- this code unlock nodes not lock them after renaming
- i'm not renaming shapes renaming transform automatically renames shape.
Comments
Post a Comment