Go to: Synopsis. Return value. Related. Flags. MEL examples.

Synopsis

getAttr [-asString] [-caching] [-channelBox] [-expandEnvironmentVariables] [-keyable] [-lock] [-multiIndices] [-settable] [-silent] [-size] [-time time] [-type] attribute

getAttr is undoable, NOT queryable, and NOT editable.

This command returns the value of the named object's attribute. UI units are used where applicable. Currently, the types of attributes that can be displayed are:

Other data types cannot be retrieved. No result is returned if the attribute contains no data.

Return value

AnyValue or state of the attribute. The number and type of values returned is dependent on the attribute type.

Related

addAttr, attributeQuery, connectAttr, disconnectAttr, listAttr, setAttr

Flags

asString, caching, channelBox, expandEnvironmentVariables, keyable, lock, multiIndices, settable, silent, size, time, type
Long name (short name) Argument types Properties
-asString(-as) create
This flag is only valid for enum attributes. It allows you to get the attribute values as strings instead of integer values. Note that the returned string value is dependent on the UI language Maya is running in (about -uiLanguage).
-caching(-ca) create
Returns whether the attribute is set to be cached internally
-channelBox(-cb) create
Returns whether the attribute is set to show in the channelBox. Keyable attributes also show in the channel box.
-expandEnvironmentVariables(-x) create
Expand any environment variable and (tilde characters on UNIX) found in string attributes which are returned.
-keyable(-k) create
Returns the keyable state of the attribute.
-lock(-l) create
Returns the lock state of the attribute.
-multiIndices(-mi) create
If the attribute is a multi, this will return a list containing all of the valid indices for the attribute.
-settable(-se) create
Returns 1 if this attribute is currently settable by setAttr, 0 otherwise. An attribute is settable if it's not locked and either not connected, or has only keyframed animation.
-silent(-sl) create
When evaluating an attribute that is not a numeric or string value, suppress the error message saying that the data cannot be displayed. The attribute will be evaluated even though its data cannot be displayed. This flag does not suppress all error messages, only those that are benign.
-size(-s) create
Returns the size of a multi-attribute array. Returns 1 if non-multi.
-time(-t) time create
Evaluate the attribute at the given time instead of the current time.
-type(-typ) create
Returns the type of data currently in the attribute.

Attributes of simple types such as strings and numerics always contain data, but attributes of complex types (arrays, meshes, etc) may contain no data if none has ever been assigned to them. When this happens the command will return with no result: not an empty string, but no result at all. Attempting to directly compare this non-result to another value or use it in an expression will result in an error, but you can assign it to a variable in which case the variable will be set to the default value for its type (e.g. an empty string for a string variable, zero for an integer variable, an empty array for an array variable). So to be safe when using this flag, always assign its result to a string variable, never try to use it directly.


Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can be used more than once in a command.

MEL examples

createNode revolve -n gravityWell;
sphere -n loxTank;
cone -n noseCone;
cone -n fin;
pointConstraint -n weld fin noseCone;

float  $angle    = `getAttr gravityWell.esw`;
// Result: 360 //
string $type     = `getAttr -type loxTank.translate`;
// Result: double3 //
int    $lock     = `getAttr -lock noseCone.translateX`;
// Result: 0 //
float  $finZ     = `getAttr -time 12 fin.translateZ`;
// Result: 0 //
int    $size     = `getAttr -size weld.target`;
// Result: 1 //
int    $size     = `getAttr -settable weld.target`;
// Result: 0 //
float  $matrix[] = `getAttr loxTank.matrix`;
// Result: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 //
createNode file -n file1;
setAttr file1.ftn -type "string" "$TMPDIR/smile.gif";
string $s = `getAttr file1.ftn`;
// Result: $TMPDIR/smile.gif //
string $s = `getAttr -x file1.ftn`;
// Result: /var/tmp/smile.gif //

// Get the list of all used indices on a multi attribute
getAttr -multiIndices initialShadingGroup.dagSetMembers
// Result: 0 1 2 //