4.18.4 Attribute class

The Attribute class can be used to convert the value of an attribute (as specified by the setAttr MEL command) into an appropriate Python value.

An Attribute object is initialized with the arguments that were passed to the onSetAttr() callback of the reader class. The value can be retrieved using the getValue() method. Whenever you have prior knowledge of the node you are currently processing you should pass the expected type of the attribute to the getValue() method to prevent the method from having to guess the type in case it is not specified in the setAttr call.

class Attribute( attr, vals, opts)

attr, vals and opts are the arguments of the onSetAttr() callback of the MAReader class.

getBaseName( )
Return the base name of the attribute. This is the first part of the attribute name (and may actually refer to another attribute).

  ".t"            -> "t"
  ".ed[0:11]"     -> "ed"
  ".uvst[0].uvsn" -> "uvst"

getFullName( )
Return the full attribute specifier.

getValue( type=None, n=None)
Return the value of the attribute as an appropriate Python value. type is a string containing the required type of the value. If None is passed, the method tries to retrieve the value from the attribute itself. If it fails, an exception is thrown. The following table lists the valid type strings and their corresponding Python type:

type Python type
"bool" bool
"int" int
"float" float
"string" str
"short2" (int, int)
"short3" (int, int, int)
"long2" (int, int)
"long3" (int, int, int)
"int32Array" [int, ...]
"float2" (float, float)
"float3" (float, float, float)
"double2" (float, float)
"double3" (float, float, float)
"doubleArray" [float, ...]
"polyFaces" PolyFace (see 4.18.5)
"nurbsSurface" NurbsSurface (see 4.18.6)
"nurbsCurve" NurbsCurve (see 4.18.7)

The argument n specifies how many values are expected. An exception is thrown if the number of values that were set by the setAttr call doesn't match the required number. If None is passed, an arbitrary number of values is allowed. The value of n also influences the return type. If the value is 1 the method will return one of the types in the above table, otherwise it will return a list of the above types.