Go to: Synopsis. Return value. Related. Flags. Python examples.
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 NOT undoable, NOT queryable, and NOT editable.
This command returns the value of the named object's attribute.
For Ufe attributes, the input attribute string should be
"<ufe_path_string>.<ufe_attribute_name>".
UI units are used where applicable.
Currently, the types of attributes that can be displayed are:
- numeric attributes
- string attributes
- matrix attributes
- numeric compound attributes (whose children are all numeric)
- vector array attributes
- double array attributes
- int32 array attributes
- point array attributes
- data component list attributes
- Ufe attributes
Other data types cannot be retrieved. No result is returned if the
attribute contains no data.
Any | Value or state of the attribute. The number and type
of values returned is dependent on the attribute type. |
addAttr, attributeQuery, connectAttr, disconnectAttr, listAttr, setAttr
asString, caching, channelBox, expandEnvironmentVariables, keyable, lock, multiIndices, settable, silent, size, time, type
Long name (short name) |
Argument types |
Properties |
|
asString(asString)
|
boolean
|
|
|
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).
Not supported for Ufe attributes.
|
|
caching(ca)
|
boolean
|
|
|
Returns whether the attribute is set to be cached internally
Not supported for Ufe attributes.
|
|
channelBox(cb)
|
boolean
|
|
|
Returns whether the attribute is set to show in the Channel Box.
Keyable attributes also show in the Channel Box.
Not supported for Ufe attributes. The display of Ufe attributes in
the Channel Box is controlled using the channelBox command flag
-ual/ufeFixedAttrList.
|
|
expandEnvironmentVariables(x)
|
boolean
|
|
|
Expand any environment variable and (tilde characters on UNIX)
found in string attributes which are returned.
Not supported for Ufe attributes.
|
|
keyable(k)
|
boolean
|
|
|
Returns the keyable state of the attribute.
Not supported for Ufe attributes.
|
|
lock(l)
|
boolean
|
|
|
Returns the lock state of the attribute.
|
|
multiIndices(mi)
|
boolean
|
|
|
If the attribute is a multi, this will return a list containing
all of the valid indices for the attribute.
Not supported for Ufe attributes.
|
|
settable(se)
|
boolean
|
|
|
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.
For Ufe attributes an attribute is settable if it's not locked.
|
|
silent(sl)
|
boolean
|
|
|
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.
Not supported for Ufe attributes.
|
|
size(s)
|
boolean
|
|
|
Returns the size of a multi-attribute array. Returns 1 if non-multi.
Not supported for Ufe attributes.
|
|
time(t)
|
time
|
|
|
Evaluate the attribute at the given time instead of the current time.
Not supported for Ufe attributes.
|
|
type(typ)
|
boolean
|
|
|
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 have multiple arguments, passed either as a tuple or a list.
|
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] #