I have a script in Maya that looks for a shader and creates it if this shader doesn't exist. So far, so good. The problem is, that I can't seem to make Maya store it from its name, when it is found.
import maya.cmds as cmds
findShd = cmds.objExists( 'shd_' + str( udim ) )
if findShd:
print 'shader exists'
shaders = cmds.ls( 'shd_' + str( udim ) )
print shaders[ 0 ] # this prints the name as I would expect
shaderSG = mc.listConnections( shaders[ 0 ], type = 'shadingEngine' )
else:
shader = cmds.shadingNode( 'blinn', asShader = True, name = ( 'shd_' + str( udim ) ) )
shaderSG = cmds.sets( shader, renderable = True, noSurfaceShader = True, empty = True, name = shader + "SG" )
cmds.connectAttr( shader + ".outColor", shaderSG + ".surfaceShader", force = True )
cmds.select( shellUVs )
lFaces = cmds.ls( cmds.polyListComponentConversion( tf = True ) )
for face in lFaces:
cmds.sets( lFaces, e = True, forceElement = shaderSG )
When the shader exists, I need to store both it and the shading group it is attached to, so that I can assign it outside of the condition.
This line though:
shaderSG = cmds.listConnections( shaders[ 0 ], type = 'shadingEngine' )
gives me: Module object has no attribute listConnections
How should I store it, if not with list?
Thanks.
I think you messing up with maya module namespaces Try with cmds
shaderSG = cmds.listConnections(shaders[0],type='shadingEngine')