PDA

View Full Version : Python Loops strange behaviour...


Michael-Williamson
02-08-2008, 02:05 PM
I know this is the mel forum, but in lieu of a python forum...

I'm using Maya as a platform to export data into someone elses toolchain so all my assets are imported..
I'm writing some scripts to do cleanup and pre processing before export ( I have some prior knowledge of python so chose it over mel which I know nothing about), came across a weird stumbling block
import maya.cmds as mc

def TruncateNodes(myName):
allNodes = mc.ls(l=True)
length = len(myName)
for n in allNodes:
#check id this is an imported node and rename
if n[:length] == myName:
#this is a node to re-name!
newName = n[length:]
print "Re-name node '"+ n + "' to '"+newName+"'"
mc.rename(n,newName)
mc.refresh()


TruncateNodes("TestOBJ_32_")

The above function is to strip out some garbage that my exporter puts in every node.

The print function indicates that the variables are getting the right names, but the mc.rename line is not actually renaming the nodes....

if I set n and newname as variables outside of this function

n="pCube1"
newName ="susan"
mc.rename(n,newName)

than the node is renamed fine.

What am i doing wrong?

T1ckL35
02-08-2008, 10:43 PM
Once or twice I've had a similar thing.
Try declaring the variables in question as strings in the rename function in case it expects a string name and not an object.

str(value)

Also the help files mention namespaces and potential issues to be aware of.

Simon

CGTalk Moderation
02-08-2008, 10:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.