Preview:
global proc windowUsefulDemo()
{
	string $win = `window -t "Make Colourful Cubes" -wh 600 100`;
	rowColumnLayout -nc 1 -cw 1 600;
	string $amountSlider = `intSliderGrp -l "How Many?" -f 1 -cw 1 80`;
	string $colourSlider = `colorSliderGrp -l "What Colour?" -rgb 0.572002 0.838 0.069554 -cw 1 80`;
	button -l "Create" -c ("createCubes "+$amountSlider+" "+$colourSlider); // send the slider names
	button -l "Close" -c ("deleteUI -wnd "+$win); 
	showWindow $win;
}

proc createCubes(string $amountSlider, string $colourSlider) // makeCubes expects the slider names (as strings)
{
	int $num = `intSliderGrp -q -v $amountSlider`; // query the value from the intSliderGrp
	float $col[] = `colorSliderGrp -q -rgb $colourSlider`; // query the colour from the colorSliderGrp

	string $allCubes[];

	for ($c=0;$c<$num;$c++) // queried int value used here
	{
		string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
		$allCubes[$c] = $cubeName[0];
	}

	string $mat = `shadingNode -asShader blinn`;
	string $sg = `sets -renderable true -noSurfaceShader true -empty -name ($mat+"SG")`;
	connectAttr -f ($mat+".outColor") ($sg+".surfaceShader");
	setAttr ($mat+".color") -type double3 $col[0] $col[1] $col[2]; // queried colour used here


	select -r $allCubes;
	string $groupName = `group`;
	select -r $groupName;
	sets -e -forceElement $sg;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter