ApplyColorToObjectSafe MEL
From scripting
I made this modified shader function from my older ApplyColorToObject command because I sometimes would get a naming error. The old function, if the name already existed in the file, would kill the script due to naming conflicts. This should resolve that conflict.
global proc string ApplyColorToObjectSafe(string $ObjName, string $MatType, float $RVal, float $GVal, float $BVal, string $ShaderName, int $Counter) { //Nick Pisca 0001d 2011. //ApplyColorToObjectSafe("pTorus1", "lambert", 0.1, 0.1, 0.2, "CurShad", 23); //string $ObjName="extrudedSurface1"; string $MatType="blinn"; float $RVal=0.3; float $GVal=0.8; float $BVal=0.3; string $ShaderName="HH"; int $Counter=6; string $NL = $ShaderName; string $nicklambert = $NL+$Counter; string $TRK = `shadingNode -asShader $MatType -n $nicklambert`; string $nicklambert = $TRK; string $nicklambertSG = $TRK+"SG"; //$NL+$Counter+"SG"; string $nicklambertoutcolor = $TRK+".outColor"; //$NL+$Counter+".outColor"; string $nicklambertSGsS = $TRK+"SG.surfaceShader"; //$NL+$Counter+"SG.surfaceShader"; string $nicklambertcolor = $TRK+".color"; //$NL+$Counter+".color"; sets -renderable true -noSurfaceShader true -empty -name $nicklambertSG; connectAttr -f $nicklambertoutcolor $nicklambertSGsS; select -r $ObjName ; sets -e -forceElement $nicklambertSG; setAttr $nicklambertcolor -type "double3" $RVal $GVal $BVal; return $nicklambert; }
Related Commands: ApplyColorToObject
More information on applying materials, read pages 128-133 in YSYT.