Getting and setting multi-value attributes

Some nodes have attributes that contain multiple values. The way Maya stores the values does not correspond to a MEL datatype.

For example:

In the online node documentation, the type of these attributes will be listed as something similar to 3float, indicating the attribute stores 3 float values.

Getting multi-values

You can get individual values from a multi-valued attribute using an index similar to the way you get an individual element from an array:

getAttr nurbsSphere2.translate[1];
getAttr nurbsSphereShape2.cv[0][2];

You can also assign the multiple values to an array:

// Put the three values in the translate
// attribute in an array:
float $trans[] = getAttr("nurbsSphere2.translate");
// Result: -2.76977 0 0 //
// Put the X, Y, and Z positions of cv #1 of curveShape1
// in an array:
float $cvXYZ[] = getAttr("curveShape1.cv[1]");
// Result: -2.367282 0 2.491355 //
// Put the X, Y, and Z positions of cv U=1,V=2
// of nurbsSphereShape2 in an array:
float $cvXYZ_2[] = getAttr("nurbsSphereShape2.cv[1][2]");
// Result: -2.367282 0 2.491355 //

Setting multi-values

Although you can get multi-values all at once as an array as shown above, the reverse does not work: you cannot assign an array to a multi-value attribute:

setAttr("nurbsSphere2.translate",{1.0, 1.2, 3.4});
// ERROR

Instead, you pass multiple arguments to setAttr:

setAttr("nurbsSphere1.translate", 1.0, 1.2, 3.4);
setAttr("curveShape1.cv[1]", 1.0, 1.2, 3.4);
setAttr("nurbsSphereShape1.cv[1][2]", 5.5, -2.3, 0);

To change only one part of a multi-value, you could put the multi-value into an array, then modify the contents of the array and put them back into the multi-valued attribute:

// Change only the second part of the translate multi-value
float $trans = getAttr("nurbsSphere.translate");
$trans[1] += 2;
setAttr("nurbsSphere.translate",$trans[0],$trans[1],$trans[2]);

However this situation will not really arise in practice, since multi-valued attributes have singular equivalents (such as translate and translateX, translateY, and translateZ) as well as a simple command equivalent, in this case:

move -relative 0 2 0 "nurbsSphere1";

Wildcards

You can use the string “*” in the index on a multi-value attribute to represent every value.

For example:

// Get the translation of every CV along U=1
getAttr nurbsPlaneShape1.cv[1]["*"];
// Result: 0 0 0 0 0.456295 0 0 0.456295 0 0 0 0 //
// Get the translation of every CV.
getAttr nurbsPlaneShape1.cv["*"]["*"];
// Result: 0 -0.520965 0 0 0 0 0 0 0 0 -0.520965 0 0 0 0 0 0.456295 0 0 0.456295 0 0 0 0 0 0 0 0 0.456295 0 0 0.456295 0 0 0 0 0 -0.520965 0 0 0 0 0 0 0 0 0.702647 0 //
// Select every CV of a surface:
select -r nurbsSphere1.cv["*"]["*"];
// Select every CV of a curve:
select -r curve1.cv["*"] ;