// Assigns a color to each face of a mesh. // 1 Select the objects. // 2 Execute this command, addFaceColorPrimVar("mycolor", <<0,0,0>>,<<1,1,1>>); global proc addFaceColorPrimVar(string $shortname, vector $minval, vector $maxval) { string $sel[] = `ls -sl`; string $fullname = "rmanuC" + $shortname; for($current in $sel) { string $shapes[] = `listRelatives -s $current`; string $shape = $shapes[0]; if(attributeExists($fullname, $shape) == 0) { addAttr -ln $fullname -sn $fullname -dt vectorArray -k 1 $shape; } int $numFaces[] = `polyEvaluate -f $shape`; string $dataStr = $numFaces[0] + " "; float $r, $g, $b; for($n = 0; $n < $numFaces[0]; $n++) { vector $rgb = rand($minval, $maxval); float $r = $rgb.x; float $g = $rgb.y; float $b = $rgb.z; $dataStr = $dataStr + $r + " " + $g + " " + $b + " "; } eval("setAttr " + $shape + "." + $fullname + " -type vectorArray " + $dataStr); } }