Attribute names
When specifying an attribute, however, you cannot use the attribute names you normally see in the Channel Box, because these may contain spaces. Instead you can use the attribute long or short names (choose Channels → Channel Names in de Channel Box).
Furthermore, you must always combine the name of the attribute with the name of the object or node, in the form node.attribute.
Retrieving attribute values
You can retrieve the value of an attribute using the getAttr function. There are two alternative ways of writing this:
float $ypos = getAttr("pCube1.translateY");
float $ypos = `getAttr pCube1.translateY`;
Modifying attribute values
You can modify the value of an attribute using the setAttr command. Here too, there are two alternative ways of writing this
setAttr pCube1.translateY 15;
setAttr("pCube1.translateY", 10);
Custom attributes
You can also add your own attributes to an object, in order to store extra information with respect to the object (e.g., mass, speed or cost).
When you create an attribute you must at least specify its name (long or short) and its type. This type is not exactly the same as the data type of a variable.
Attribute type | Possible values |
bool | boolean values (0 or 1 or on or off) |
long | long integers |
short | short integers (-32768 to +32767) |
double | double precision floating-point numbers |
"float" | single precision floating-point numbers |
addAttr -shortName gf -longName goForwards pCube1;
addAttr -ln vX -attributeType double;
addAttr -sn ms -ln mass -defaultValue 1.0 -minValue 0.001 -maxValue 10000;