Reputation: 1
I am working on a python script(maya3d software) to 'rename mesh as per group name'. After running the script an error is coming maybe because I have same shape node name in two groups. Here's the error message:
Error: RuntimeError: file line 8: More than one object matches name
The script is working fine if the object is with a unique name. I found something to ignoreShape
in rename page, but it's not working.
Here's the link: https://download.autodesk.com/us/maya/2009help/CommandsPython/rename.html?&_ga=2.14607159.1860356590.1585850032-633810306.1580653271#flagignoreShape
Here's the script:
import maya.cmds as cmds
import maya.cmds as cmds
selection = cmds.ls( selection=True )
for each in selection:
groupName = cmds.ls(each, selection=True )
children = cmds.listRelatives(groupName, children=True)
for count,obj in enumerate(children):
cmds.rename(obj,groupName[0]+str(count+1).zfill(2)+'_GEO')
selection = cmds.ls( selection=True )
for each in selection:
groupName = cmds.ls(each, selection=True )
children = cmds.listRelatives(groupName, children=True)
for child in children:
newname=child.replace('_GRP','_')
cmds.rename(child,newname)
Can anybody help me with this, please. Thanks.
Upvotes: 0
Views: 1110
Reputation: 1793
Here's the modified code:
import maya.cmds as cmds
selection = cmds.ls(selection=True)
# group_name will contain the group name, no need to query again
for group_name in selection:
# The key is to query the full path, so you'll get
# "|aa_GRP|pCube1" (which is unique) instead of "pCube1" (which is not)
children = cmds.listRelatives(group_name, children=True, fullPath=True)
for i, obj in enumerate(children, start=1):
cmds.rename(obj, '{group}{number:02}_GEO'.format(
group=group_name,
number=i))
Upvotes: 1