
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Guys,
I have created a script which will automatically connect textures to the respective attribute of shaders. but sometimes we are not using some textures then it is having an issue. Maya is giving an error:
# Error: IndexError: file <maya console> line 20: list index out of range #
Now, I am trying to use "if, elif" , which is not working.
Please have a look at the script below, Let me know what will be the solution for this. Thanks.
import maya.cmds as cmds
DIF = cmds.ls('*DIF*', sl=True)
RGH = cmds.ls('*RGH*', sl=True)
NRM = cmds.ls('*NRM*', sl=True)
MTL = cmds.ls('*MTL*', sl=True)
EMI = cmds.ls('*EMI*', sl=True)
MAT =cmds.shadingNode("aiStandardSurface",asShader=True, n='aiStandardSurface1')
if cmds.isTrue(RGH):
cmds.connectAttr(RGH[0]+'.outColorR',MAT+'.specularRoughness')
elif cmds.isTrue(DIF):
cmds.connectAttr(DIF[0]+'.outColor',MAT+'.baseColor')
elif cmds.isTrue(MTL):
cmds.connectAttr(MTL[0]+'.outColorR',MAT+'.metalness')
else:
print(' ')
Solved! Go to Solution.