+ Chapter - 07 - MEL - Attributes +
Instructor - Pradeep Mamgain
+ Overview +
Attribute (MEL term Attr) is any item that lives inside the Maya node. For example a transform node has attributes for the amount of rotation in X, Y and Z. You can think of Attributes as variables that holds value of a certain data type. You can build, rotate, scale or animate one or more attributes of a node. A full attribute name has the name of the node, a period and name of the attribute in the node.
nodeName.attributeName
For example, nurbsSphere.translateX.
Node name can be found at the top of the Attribute Editor.
+ Long/Short Names of Attributes +
By default Maya displays "Nice" names for attributes in channel editor, as seen in Figure - 7.1. You can change them to MEL compatible Long or Short names, as seen in Figure - 7.2 and Figure 7.3. To change this click on the channel menu of the channel editor and then select Channel Names > Long or Short, as seen in Figure - 7.4.

Figure - 7.1, Nice Names.

Figure - 7.4, Channels Names Menu.
By default, channel editor does not display all the attributes associated with a node, to see all of them, go to Windows > General Editors > Channel Control. Figure - 7.5, displays the Channel Control window.

Figure - 7.5, Channel Control Window.
+ listAttr Command +
listAttr command displays all attributes of an object. If no flags are specified, all the attributes are displayed.
Synopsis
listAttr [-array] [-caching] [-changedSinceFileOpen] [-channelBox] [-connectable] [-hasData] [-keyable] [-leaf] [-locked] [-multi] [-output] [-read] [-readOnly] [-scalar] [-scalarAndArray] [-settable] [-shortNames] [-string string] [-unlocked] [-userDefined] [-visible] [-write] [objects]
Hands on : Displaying all attributes of a nurbsSphere
Download project files and open ch07_lstAttr_command.mb. It has a nurbs sphere called nurbsSphere1. Open the script editor and paste Example - 7.1, in the input area of the script editor. Execute the script.
Example 7.1 - Displaying all attributes of a nurbsSphere
string $lstA, $lstAttributes[];
$lstAttributes=`listAttr nurbsSphere1`;
for ($lstA in $lstAttributes)
{
print ($lstA + "\n");
}
lstAttr command returns an array of attributes, that is why we have declared a string array first. Array returned by the lstAttr command is stored in string variable $lstAttributes. Notice the back ticks that surrounds the command listAttr nurbsSphere1 statement. MEL uses those ticks whenever you want to extract information from a command. We will also use them in getAttr command. Back tick key is right next to 1 key or above Tab key on windows keyboard. Next we used a for..in loop to extract and print values from the array that is returned by the lstAttr command.
Example - 7.1, when executed will print following in script editor.
message
caching
isHistoricallyInteresting
nodeState
binMembership
boundingBox
boundingBoxMin
boundingBoxMinX
boundingBoxMinY
boundingBoxMinZ
boundingBoxMax
boundingBoxMaxX
boundingBoxMaxY
boundingBoxMaxZ
boundingBoxSize
boundingBoxSizeX
boundingBoxSizeY
boundingBoxSizeZ
center
boundingBoxCenterX
boundingBoxCenterY
....
And list goes on.
You can use lots of flags with the lstAttr command, check command's documentation for more details.
+ setAttr Command +
Synopsis
SetAttr [flags] object.attribute value [value..]
ReturnValue None.
setAttr command sets the value of a node. When Example - 7.2 is executed sphere moves 10 units up in the Y direction. Line 2 locks the translateY attribute. Line 3 makes translateZ attribute non-keyable.
Example - 7.2, setAttr command in action.
setAttr nurbsSphere1.translateY 10;
setAttr -lock on nurbsSphere1.translateY;
setAttr -keyable off nurbsSphere1.translateZ;
Result of Example 7.2 is as seen in Figure - 7.6.

Figure - 7.6, setAttr command in action.
You can get or set an element of a particle vector or float array using the getParticleAttr and setParticleAttr commands. We will learn about these commands in later chapters.
ANIMATION EXPRESSIONS
In animation expressions, you do not have to use the getAttr and setAttr commands. Simply use the node/attribute name in expressions
nurbsSphere1.translateX = nurbsSphere1.translateY / 2 ;
+ getAttr Command +
getAttr [-asString] [-caching] [-channelBox] [-expandEnvironmentVariables] [-keyable] [-lock] [-multiIndices] [-settable] [-silent] [-size] [-time time] [-type] object.attribute
getAttr command returns the value of named object's attribute.
print(`getAttr nurbsSphere1.translateY`); // Displays 10.
float $trY=`getAttr nurbsSphere1.translateY`; // Stores value 10 as type float in variable $trY.
DATA TYPE OF ATTRIBUTES
Like variables, each attribute has a data type. Common data types are floats and booleans. Other data types like integers, floats and vectors are less common. Vector array data type are particularly useful in particles attributes which are made of three components, like three values for Red, Blue and Green color. Apart from this maya has per particle attributes, that we will discuss in particle section. Particle shape nodes also have compound data type that is not common in other objects.
+ What Next ? +
In this chapter we leant a lot about attributes. In next chapter we will talk little bit about the styling of the MEL script.
+ Download Project +
Dear guest, Only registered members can download projects/footages/scripts and Video files.Kindly get registered to download the files. It will also help us in informing you that when new tutorial/article/resource or cg news is available. Once you get registered downlaod link will appear here. - Downloaded times.
+ Save / Promote This Article/Tutorial/Information: +
If you enjoyed this article your vote is always highly appreciated.+ Other Info +
+ Discuss in Forums