pymel.core.general.getAttr

getAttr(attr, default=None, **kwargs)

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: numeric attributesstring attributesmatrix attributesnumeric compound attributes (whose children are all numeric)vector array attributesdouble array attributesint32 array attributespoint array attributesdata component list attributesOther data types cannot be retrieved. No result is returned if the attribute contains no data.

Maya Bug Fix:
  • maya pointlessly returned vector results as a tuple wrapped in a list ( ex. ‘[(1,2,3)]’ ). This command unpacks the vector for you.
Modifications:
  • casts double3 datatypes to Vector
  • casts matrix datatypes to Matrix
  • casts vectorArrays from a flat array of floats to an array of Vectors
  • when getting a multi-attr, maya would raise an error, but pymel will return a list of values for the multi-attr
  • added a default argument. if the attribute does not exist and this argument is not None, this default value will be returned
  • added support for getting message attributes

Flags:

Long Name / Short Name Argument Types Properties
asString / asString bool ../../../_images/create.gif
  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 bool ../../../_images/create.gif
  Returns whether the attribute is set to be cached internally
channelBox / cb bool ../../../_images/create.gif
  Returns whether the attribute is set to show in the channelBox. Keyable attributes also show in the channel box.
expandEnvironmentVariables / x bool ../../../_images/create.gif
  Expand any environment variable and (tilde characters on UNIX) found in string attributes which are returned.
keyable / k bool ../../../_images/create.gif
  Returns the keyable state of the attribute.
lock / l bool ../../../_images/create.gif
  Returns the lock state of the attribute.
multiIndices / mi bool ../../../_images/create.gif
  If the attribute is a multi, this will return a list containing all of the valid indices for the attribute.
noEvaluation / ne bool ../../../_images/create.gif
  Instead of reevaluating dirty values just return the value that is currently available in the node, if any.
settable / se bool ../../../_images/create.gif
  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 bool ../../../_images/create.gif
  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 bool ../../../_images/create.gif
  Returns the size of a multi-attribute array. Returns 1 if non-multi.
time / t time ../../../_images/create.gif
  Evaluate the attribute at the given time instead of the current time.
type / typ bool ../../../_images/create.gif
  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 have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.getAttr

Example:

import pymel.core as pm

pm.createNode( 'revolve', n='gravityWell' )
# Result: nt.Revolve(u'gravityWell') #
pm.sphere( n='loxTank' )
# Result: [nt.Transform(u'loxTank'), nt.MakeNurbSphere(u'makeNurbSphere1')] #
pm.cone( n='noseCone' )
# Result: [nt.Transform(u'noseCone'), nt.MakeNurbCone(u'makeNurbCone1')] #
pm.cone( n='fin' )
# Result: [nt.Transform(u'fin'), nt.MakeNurbCone(u'makeNurbCone2')] #
pm.pointConstraint( 'fin', 'noseCone', n='weld' )
# Result: nt.PointConstraint(u'weld') #

angle = pm.getAttr('gravityWell.esw')
type = pm.getAttr('loxTank.translate',type=True)
lock = pm.getAttr('noseCone.translateX',lock=True)
finZ = pm.getAttr('fin.translateZ',time=12)
size = pm.getAttr('weld.target',size=True)
size = pm.getAttr('weld.target',settable=True)
matrix = pm.getAttr('loxTank.matrix')
pm.createNode('file',n='file1')
# Result: nt.File(u'file1') #
pm.setAttr( 'file1.ftn', '$TMPDIR/smile.gif',type='string' )
s = pm.getAttr('file1.ftn')
s = pm.getAttr('file1.ftn',x=True)

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