Shader texture file not found

Skip to first unread message

Anastasia Korol

Jun 16, 2021, 1:23:17 AMJun 16
to Python Programming for Autodesk Maya
Hi guys! I am beginner in Python and need a little bit of help with locating a path for texture file in Maya. It is a lambert shader with layered texture node and 3 texture files which I need to define. Hopefully it is the right chat to seek for help with such a noob question. The shader creating works perfectly so the only thing is texture file error when maya can't find the texture file path at all:

Thank you!

Marcus Ottosson

Jun 16, 2021, 1:52:51 AMJun 16

Hi Anastasia, welcome to the forum! In Python, the \ character is a special character for escaping other characters. E.g. \n means “newline”. In your example, the \ is used in your path:

file1 = ("C:\Users\User\Download\swatch_arles-yellow__6094-42.png")

You can either keep it, and prepend a r to make it a “raw string”, like so:

file1 = (r"C:\Users\User\Download\swatch_arles-yellow__6094-42.png")

Which informs Python to “hey, don’t give special treatment to any of these characters”. Or you can replace \ for /, Windows is OK with that syntax. You can also remove the parentheses since they are not needed.

There might be other issues with your snippet, but this is definitely one of them.

You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Anastasia Korol

Jun 16, 2021, 2:01:06 AMJun 16
Thank you so much! Such a hilarious mistake

The other thing I found out is that the fileNode is always being created as a new one for example fileNode12, etc and the texture node is connected to it and can't work with fileNode12 since in setAttr there is a specific format of fileNode1 ( cmds.setAttr("{}.fileTextureName".format(fileNode1), file1, type="string") )

I am sure it is a simple thing connected with usage of string type in the right way. If somebody has an idea how to fix it, let me know!
Thank you

tomas mikulak

Jun 16, 2021, 2:51:40 AMJun 16
Hi Anastasia,
it is better to create nodes yourself to have more control over it. But then you would have to do some operations maya does automatically. or just find proc that does it.

I use this definition to add shader to specific mesh. In my case name of texture and mesh have some conventions. but variables are mesh name and file path so it should be ok

import maya.cmds as mc

def createShader(name,texturePath):
#name = 'test'
attrList = ['coverage','translateFrame','rotateFrame','mirrorU','mirrorV','stagger','wrapU','wrapV','repeatUV','offset','rotateUV','noiseUV','vertexUvOne','vertexUvTwo','vertexUvThree','vertexCameraOne','outUV','outUvFilterSize']
#create shader --- shadingNode -asShader surfaceShader;
shd = mc.shadingNode('surfaceShader', asShader=True,name =name+'_SHD')
#create shading engine --- sets -renderable true -noSurfaceShader true -empty -name surfaceShader1SG;
shdSg = mc.sets(renderable=True, noSurfaceShader = True, empty = True, name = shd+'_SG')
#connect --- connectAttr -f surfaceShader1.outColor surfaceShader1SG.surfaceShader;
mc.connectAttr(shd+'.outColor', shdSg+'.surfaceShader')
#create file node
fNode = mc.shadingNode('file',asTexture = True, isColorManaged = True, name = name+'_TXT')
#create 2dPalce
placeNode = mc.shadingNode('place2dTexture', asUtility = True, name = name+'_p2D')
#connets attrs
for a in attrList:
if a == 'outUV':
elif a == 'outUvFilterSize':
#connect to shaader
mc.connectAttr(fNode+'.outColor', shd+'.outColor')

#link texture
txtPath = os.path.join(texturePath,name+'.tif')
if os.path.isfile(txtPath):
mc.setAttr(fNode+'.fileTextureName', txtPath,type='string')
#create luminance
lumi = mc.shadingNode('luminance', asUtility=True, name = name+'_lum')
mc.connectAttr(fNode+'.outAlpha', lumi+'.valueR')
mc.connectAttr(fNode+'.outAlpha', lumi+'.valueG')
mc.connectAttr(fNode+'.outAlpha', lumi+'.valueB')
fMask = mc.shadingNode('floatMask', asUtility=True, name = name+'_fM')
mc.connectAttr(lumi+'.outValue', fMask+'.mask')
mc.connectAttr(fMask+'.outFloat', shd+'.outTransparencyR')
mc.connectAttr(fMask+'.outFloat', shd+'.outTransparencyG')
mc.connectAttr(fMask+'.outFloat', shd+'.outTransparencyB')
#assign to mesh,r=True)
mc.sets(forceElement=shdSg,e=True )

st 16. 6. 2021 o 8:01 Anastasia Korol <> napísal(a):

Anastasia Korol

Jun 16, 2021, 2:18:29 PMJun 16
to Python Programming for Autodesk Maya
Thank you! I found out how to fix the string in my version but it is definitely a helpful script to take a look for me in the future to learn :)
Reply all
Reply to author
0 new messages