// Comment the attributes you do NOT wish to add to the selected object.
// Then execute the MEL code in Maya's script editor (MEL tab).
addColorAttr("patcolor",1,0,0);
addColorAttr("bakcolor",1,1,1);
addFloatAttr("cutoff",0.5);
// Assumes the transform node and NOT the shape node of an object is selected.
proc addFloatAttr(string $name, float $value) {
string $sel[] = `ls -sl`;
for($current in $sel) {
string $shapes[] = `listRelatives -s $current`;
string $shape = $shapes[0];
if(attributeExists($name, $shape) == 0)
addAttr -ln $name -sn $name -k 1 $shape;
setAttr ($shape + "." + $name) $value;
}
}
proc addColorAttr(string $name, float $r, float $g, float $b) {
string $sel[] = `ls -sl`;
for($current in $sel) {
string $shapes[] = `listRelatives -s $current`;
string $shape = $shapes[0];
if(attributeExists($name, $shape) == 0) {
addAttr -ln $name -sn $name -at "float3" -usedAsColor -k 1 $shape;
$red = $name + "_r";
$green = $name + "_g";
$blue = $name + "_blue";
addAttr -ln $red -at "float" -k 1 -parent $name $shape;
addAttr -ln $green -at "float" -k 1 -parent $name $shape;
addAttr -ln $blue -at "float" -k 1 -parent $name $shape;
}
setAttr ($shape + "." + $name) -type "float3" $r $g $b;
}
}
proc addVectorAttr(string $name, float $r, float $g, float $b) {
string $sel[] = `ls -sl`;
for($current in $sel) {
string $shapes[] = `listRelatives -s $current`;
string $shape = $shapes[0];
if(attributeExists($name, $shape) == 0) {
addAttr -ln $name -sn $name -at "float3" -k 1 $shape;
$red = $name + "_r";
$green = $name + "_g";
$blue = $name + "_blue";
addAttr -ln $red -at "float" -k 1 -parent $name $shape;
addAttr -ln $green -at "float" -k 1 -parent $name $shape;
addAttr -ln $blue -at "float" -k 1 -parent $name $shape;
}
setAttr ($shape + "." + $name) -type "float3" $r $g $b;
}
}
proc addStringAttr(string $name, string $value) {
string $sel[] = `ls -sl`;
for($current in $sel) {
string $shapes[] = `listRelatives -s $current`;
string $shape = $shapes[0];
if(attributeExists($name, $shape) == 0)
addAttr -ln $name -nn $name -dt "string" $shape;
setAttr ($shape + ("." + $name)) -type "string" $value;
}
}