Give each vert a random vertex color script in Maya

May 28, 2022

Here's a mel script to set the green channel to a random value. Select a mesh or meshes then run it. Change the numbers after "rand" to constrain the values. -g can be -rgb with 3 numbers after it to set all rgb channels.

string $listOfObjects[] = `ls -sl`;

int $i;
for( $i = 0; $i < size($listOfObjects); $i++ )
{
	int $eval[] = `polyEvaluate -v`;
	int $numVertices = $eval[0];
	int $v;
	for( $v = 0; $v < $numVertices; $v++ )
	{
	    float $rand = `rand 0.0 1.0`;
		polyColorPerVertex -g $rand ($listOfObjects[$i] + ".vtx[" + $v + "]");
	}
}