ApplyColorToObject

From scripting
Jump to: navigation, search
ApplyColorToObject("pTorus1", "lambert", 0.1, 0.1, 0.2, "CurShad", 23);

global proc string ApplyColorToObject(string $ObjName, string $MatType, float $RVal, float $GVal, float $BVal, string  $ShaderName, int $Counter)  {
	string $NL = $ShaderName;
	string $nicklambert = $NL+$Counter;
	string $nicklambertSG = $NL+$Counter+"SG";
	string $nicklambertoutcolor = $NL+$Counter+".outColor";
	string $nicklambertSGsS = $NL+$Counter+"SG.surfaceShader";
	string $nicklambertcolor = $NL+$Counter+".color";
	
	shadingNode -asShader $MatType -n $nicklambert;   //lambert -n $nicklambert;
	//renderCreateBarCB -asShader "surfaceShader" $MatType;
	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;
} 


More information on applying materials, read pages 128-133 in YSYT.