Why does this code not create Utility Shaders i can see in the Hypershade?
import maya.cmds as cmds
import mtoa.aovs as aovs
UtiD = cmds.createNode("aiUtility" , name="aiUtility_Red")
cmds.setAttr('aiUtility_Red.shadeMode' , 2)
cmds.setAttr('aiUtility_Red.color' , 1, 0, 0)
UtiD = cmds.createNode("aiUtility" , name="aiUtility_Green")
cmds.setAttr('aiUtility_Green.shadeMode' , 2)
cmds.setAttr('aiUtility_Green.color' , 0, 1, 0)
UtiD = cmds.createNode("aiUtility" , name="aiUtility_Blue")
cmds.setAttr('aiUtility_Blue.shadeMode' , 2)
cmds.setAttr('aiUtility_Blue.color' , 0, 0, 1)
UtiD = cmds.createNode("aiUtility" , name="aiUtility_Black")
cmds.setAttr('aiUtility_Black.shadeMode' , 2)
cmds.setAttr('aiUtility_Black.color' , 0, 0, 0)
Solved! Go to Solution.
Solved by Stephen.Blair. Go to Solution.
You need to do something like this:
import maya.cmds as cmds UtiD = cmds.shadingNode("aiUtility" , name="aiUtility_RED", asShader=True)
Thanks thats better now.
But i would need also the ShadingGroup. How do i get that?
Here's another example: it creates a shader and a ShadingGroup, then assigns the shader to the selected objects
import maya.cmds as cmds def assign_standard_surface(): name = "aiStandardSurfac sel = cmds.ls(sl=True, l=Tru shader = cmds.shadingNode( 'aiStandardSurface', asShader=True, name=name ) shadingGroup = cmds.sets( shader, renderable=True, noSurfaceShader=True, empty=True, name=name+"SG" ) cmds.connectAttr(shader+".outColor", shadingGroup+".surfaceShader", force=True cmds.sets( sel, e=True, forceElement=shadingGroup )
Thanks for the Answer but the code doesnt work.
I tried to fix it but no luck. Sorry i have no experience in scripting at all.
import maya.cmds as cmds shader = cmds.shadingNode( 'aiUtility', asShader=True, name="aiUtility_RED" ) shadingGroup = cmds.sets( shader, renderable=True, noSurfaceShader=True, empty=True, name="aiUtility_REDSG" ) cmds.connectAttr(shader+".outColor", shadingGroup+".surfaceShader", force=True)
Thanks Stephen i got it working.
Just in case you wonder what im trying todo here are two little scripts to get an Object ID workflow running for Maya RenderSetup.
First you need to fire up the Python script to create the needed Shaders.
Afterwards load the JSON in the RenderSetup.
https://github.com/Mudoglu/Maya_Scripts
I will upload a Tutorial next week.
Cheers