Hi.
I have an object called 'attrDest'. I wish to add a vector attribute to object called 'atVector'.
When I do this from the UI 'add attributes' menu I see the following in the script editor:
addAttr -ln atVector -at double3 |attrDest;
addAttr -ln atVectorX -at double -p atVector |attrDest;
addAttr -ln atVectorY -at double -p atVector |attrDest;
addAttr -ln atVectorZ -at double -p atVector |attrDest;
setAttr -type double3 |attrDest.atVector 0 0 0;
setAttr -e -keyable true |attrDest.atVector;
setAttr -e -keyable true |attrDest.atVectorX;
setAttr -e -keyable true |attrDest.atVectorY;
setAttr -e -keyable true |attrDest.atVectorZ; ... and, of course, I get the vector added no problem.
I have some lines in my script which attempt to do just this. The variables are $goodAttrName and $destObject. This just recreates the commands one by one into the string array $cmds[]. When all the commands are prepared, they are evaluated.
The commands are formed thus: (the very output from the 'print' command)
addAttr -ln atVector -at double3 |attrDest
addAttr -ln atVectorX -at double -p atVector |attrDest
addAttr -ln atVectorY -at double -p atVector |attrDest
addAttr -ln atVectorZ -at double -p atVector |attrDest
setAttr -type double3 |attrDest.atVector 0 0 0
setAttr -e -keyable true |attrDest.atVector
setAttr -e -keyable true |attrDest.atVectorX
setAttr -e -keyable true |attrDest.atVectorY
setAttr -e -keyable true |attrDest.atVectorZ
Which (unless I'm going COMPLETELY crazy) is exactly the same as the commands preformed by the UI addAttribute as shown above.
When these Commands are evaluated I get my vector added ok, but I also get three floating point values under them, named attrDest.atVectorX,Y & Z! Its like its ignoring the PARENT (-p) and just adding these as new attributes.
Please can anyone tell me how to add a (keyable) vector attribute in MEL sucessfully, given $goodAttrName (for the attribute name) and $destObject (for the object) ?
cheers -
Cybotic
===============================================================================
//add attr
string $cmds[9];
int $c=0;
$cmds[$c]="addAttr -ln " + $goodAttrName + " -at double3 "+$destObject;
$c++;
string $dim;
string $dims[3]={"X","Y","Z"};
for ($dim in $dims)
{
$cmds[$c]="addAttr -ln "+$goodAttrName+$dim+" -at double -p " +$goodAttrName+ " " + $destObject;
$c++;
}
$cmds[$c]="setAttr -type double3 "+$destObject+"."+$goodAttrName+ " 0 0 0";
$c++;
$cmds[$c]="setAttr -e -keyable true "+$destObject+"."+$goodAttrName;
$c++;
for ($dim in $dims)
{
$cmds[$c]="setAttr -e -keyable true "+$destObject+"."+$goodAttrName+$dim;
$c++;
}
for ($c = 0; $c < 9; $c++)
{
print($cmds[$c]+"n");
eval($cmds[$c]);
}
============================================================================