PDA

View Full Version : small error


zasid
10-31-2012, 06:44 PM
Hello,

I am a new learner of python. I am trying to change the texture path on file node through this code but the last line is giving error.I will be thankful if someone can tell me whats going on.Am I changing a tuple which is unchangable?

I am using Maya 2012.

Code :
import maya.cmds as mc

fileNodes = mc.ls(type='file')
for f in fileNodes:
attrib="%s.fileTextureName" %f
fullname=mc.getAttr(attrib)
name=fullname.split("/")[-1]
newName="/textures/"+name
mc.setAttr(attrib,newName,type="string")

Line which is giving error : mc.setAttr(attrib,newName,type="string")

error is :
mc.setAttr(attrib,newName,type="string")
# Error: 'tuple' object is not callable
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# TypeError: 'tuple' object is not callable #

kronique
11-03-2012, 02:01 AM
Hello,

I am a new learner of python. I am trying to change the texture path on file node through this code but the last line is giving error.I will be thankful if someone can tell me whats going on.Am I changing a tuple which is unchangable?

I am using Maya 2012.

Code :
import maya.cmds as mc

fileNodes = mc.ls(type='file')
for f in fileNodes:
attrib="%s.fileTextureName" %f
fullname=mc.getAttr(attrib)
name=fullname.split("/")[-1]
newName="/textures/"+name
mc.setAttr(attrib,newName,type="string")

Line which is giving error : mc.setAttr(attrib,newName,type="string")

error is :
mc.setAttr(attrib,newName,type="string")
# Error: 'tuple' object is not callable
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# TypeError: 'tuple' object is not callable #

try quotes around the name
mc.setAttr("attrib",newName,type="string")

djx
11-03-2012, 12:35 PM
@kronique: quotes around "attrib" is incorrect since attrib is already a string variable, not a name.

@zasid: I copied you code an ran it in the script editor without change (except correcting the indentation). It worked without error. So I cant see why you would get that error.

@everybody: While testing zasid's script I discovered another annoying quirk about the way maya 2013 handles missing files. I've no idea if this behavior is intentional or a bug, but if you use zasid's code to repath some fileTextures, and if the images don't actually exist in the new path, then maya will do one of two things - both of them, in my opinion, are wrong!

If the image file was originally in your current project's sourceImages folder, then the setAttr will change the path in the fileTexture, but if the image does not exist at the new location, then maya will continue to display the image from the old location. I'm talking the swatch, the viewport and in a render. As good as this might sound at first... "maya saved me once again cos I forgot to put my image in the right place"... it is counter productive if the image in the new location was meant to be different (say, for example, a hires version of the one in the project folder). In this case, if the hires image was not there I would want an error message so that I would know.

However if the original image was NOT in the sourceImages folder (in my tests it was in the images folder in the current project), then the setAttr fails to change the path at all, but no error is raised! In this case attempting to change it manually in the attribute editor does not work either, but at least if you are doing it manually you have some chance of noticing that it kept the old path. If you do it in a script and there is no error, you would generally assume that you had changed the path and move forward. Also counter productive... when the farm renders, which maybe don't have access to your local project, all fail.

Anyway, sorry to momentarily derail your thread zasid. I hope you figured out what was causing your error.

David

zasid
11-05-2012, 09:53 AM
Thanks guys for the help, This seems to work now. Since it didn't give me indentation error and there was some tuple error so I got a bit confuse. Thanks again really appreciate the help :)

CGTalk Moderation
11-05-2012, 09:53 AM
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.