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':
mc.connectAttr(placeNode+'.outUV',fNode+'.uvCoord')
elif a == 'outUvFilterSize':
mc.connectAttr(placeNode+'.outUvFilterSize',fNode+'.uvFilterSize')
else:
mc.connectAttr(placeNode+'.'+a,fNode+'.'+a)
#connect to shaader
mc.connectAttr(fNode+'.outColor', shd+'.outColor')

#link texture
txtPath = os.path.join(texturePath,name+'.tif')
#print(txtPath)
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
mc.select(name,r=True)
mc.sets(forceElement=shdSg,e=True )

st 16. 6. 2021 o 8:01 Anastasia Korol <anastasii.ko...@gmail.com>
napísal(a):

> 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
>
>
> On Tue, 15 Jun 2021 at 22:52, Marcus Ottosson <konstrukt...@gmail.com>
> wrote:
>
>> 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.
>>
>> On Wed, 16 Jun 2021 at 06:23, Anastasia Korol <anastasii.ko...@gmail.com>
>> wrote:
>>
>>> 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:
>>>
>>> https://del.dog/crafubingu.txt
>>>
>>> Thank you!
>>>
>>> --
>>> 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 python_inside_maya+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/40130504-df79-4ea6-841c-582c52d53e1bn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/40130504-df79-4ea6-841c-582c52d53e1bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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 python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB5tfBZarSreRTAX91SeA5ARduDWY-wodHzk14%3DSfbvNw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB5tfBZarSreRTAX91SeA5ARduDWY-wodHzk14%3DSfbvNw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAAZJ9HV7jL5qVK4mzt-YQWJhMhA2oO8donWL20PBDYJm9nnw6w%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAAZJ9HV7jL5qVK4mzt-YQWJhMhA2oO8donWL20PBDYJm9nnw6w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAEUzAD1owhpcMZohaXvGHRcQ9xTrDJ1NJGZDkiacyz3uRs89mg%40mail.gmail.com.

Reply via email to