Hi,
I recently started studying Python for Maya, and today found this website while looking for help,
it’s my first post and I couldn’t find any similar topic or if I did they did not help me find a solution, I apologize if it is an easy problem to fix and I could have found the solution somewhere I didn’t check
Following a tutorial I’m making a simple object renamed,
when i run it like this in Maya, it works perfectly:
def Rename () :
selection = maya.cmds.ls(selection = True)
if len(selection) == 0:
selection = maya.cmds.ls(dag = True, long = True)
selection.sort(key=len, reverse = True)
for obj in selection:
shortName =(obj.split("|")[-1])
children = maya.cmds.listRelatives(obj, children=True, fullPath=True) or []
if len(children)== 1:
child = children[0]
objType = maya.cmds.objectType(child)
else:
objType = maya.cmds.objectType(obj)
if objType == "mesh" :
suffix = "geo"
elif objType == "joint" :
suffix = "jnt"
elif objType == "nurbsCurve" :
suffix = "nCurve"
elif objType == "locator" :
suffix = "lcr"
elif objType == "camera" :
suffix = "Skipping Camera"
continue
else:
suffix = "grp"
newName = shortName + "_" + suffix
maya.cmds.rename(obj, newName)
but when i try to import it and run the rename function I get the error “… cmds not defined”
I tried adding “import maya.cmds as cmds” at the beginning of my py file, or in maya before importing, but the issue stays, any idea why?
thanks for the help