Preview:
/*********************************************************
makeCubes.mel
Creates a cloud of cubes

USAGE: makeCubes <int numberOfCubes> <float radiusOfCloud>
*********************************************************/
global proc makeCubes(int $numCubes, float $radius)
{
	string $allCubes[]; // declare an array to save the names of the cubes

	for ($c=0;$c<$numCubes;$c++)
	{
		string $cubeName[] = `polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;

		float $randTrans[] = sphrand($radius);
		float $randRot[] = sphrand(360);
		float $randScale[] = abs(sphrand(5));

		xform -t $randTrans[0] $randTrans[1] $randTrans[2] 
		      -ro $randRot[0] $randRot[1] $randRot[2]
		      -s $randScale[0] $randScale[1] $randScale[2]
		       $cubeName[0];
		$allCubes[$c] = $cubeName[0]; // use the counter to gather the names
									  // of each new cube and save it in a list
	}
	select -r $allCubes; // select all the new cubes and group them
	group;
}

/*		You can also use rand to generate random number like this:
		float $randX = rand(5);
		float $randY = rand(5);
		float $randZ = rand(5);
*/
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