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

Synopsis

getAttr( attribute , [asString=boolean], [caching=boolean], [channelBox=boolean], [expandEnvironmentVariables= boolean], [keyable=boolean], [lock=boolean], [multiIndices=boolean], [settable=boolean], [silent=boolean], [size=boolean], [time=time], [type=boolean])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

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

Any Value 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
keyable(k) boolean create
Returns the keyable state of the attribute.
lock(l) boolean create
Returns the lock state of the attribute.
type(typ) boolean create
Returns the type of data to expect at the attribute.
size(s) boolean 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.
silent(sl) boolean 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.
settable(se) boolean 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.
expandEnvironmentVariables( x) boolean create
Expand any environment variable and (tilde characters on UNIX) found in string attributes which are returned.
asString(asString) boolean 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).
channelBox(cb) boolean create
Returns whether the attribute is set to show in the channelBox. Keyable attributes also show in the channel box.
caching(ca) boolean create
Returns whether the attribute is set to be cached internally
multiIndices(mi) boolean create
If the attribute is a multi, this will return a list containing all of the valid indices for the attribute.

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 have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

cmds.createNode( 'revolve', n='gravityWell' )
cmds.sphere( n='loxTank' )
cmds.cone( n='noseCone' )
cmds.cone( n='fin' )
cmds.pointConstraint( 'fin', 'noseCone', n='weld' )

angle = cmds.getAttr('gravityWell.esw')
# Result: 360 #
type = cmds.getAttr('loxTank.translate',type=True)
# Result: double3 #
lock = cmds.getAttr('noseCone.translateX',lock=True)
# Result: 0 #
finZ = cmds.getAttr('fin.translateZ',time=12)
# Result: 0.0 #
size = cmds.getAttr('weld.target',size=True)
# Result: 1 #
size = cmds.getAttr('weld.target',settable=True)
# Result: 0 #
matrix = cmds.getAttr('loxTank.matrix')
# Result: 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 #
cmds.createNode('file',n='file1')
cmds.setAttr( 'file1.ftn', '$TMPDIR/smile.gif',type='string' )
s = cmds.getAttr('file1.ftn')
# Result: $TMPDIR/smile.gif #
s = cmds.getAttr('file1.ftn',x=True)
# Result: /var/tmp/smile.gif #

# Get the list of all used indices on a multi attribute
cmds.getAttr('initialShadingGroup.dagSetMembers', multiIndices=True)
# Result: [0, 1, 2] #