To modify multiple attributes simultaneously, you can use the Attribute Spreadsheet (Windows > General Editors > Attribute Spread Sheet).
Alternatively, you can do so via scripting.
The following example demonstrates how to explore and use MEL scripting to disable the visibility of the all selected objects in your scene.
Query the name of the Visibility attribute.
In order to modify an attribute, you must know its exact attribute name.
Select your object. In its shape node, for example pPlaneShape1, expand the Object Display section of the Attribute Editor and disable the Visibility attribute.
The MEL command associated with your action is displayed in the top pane of the Script Editor; for example:
setAttr "pPlaneShape1.visibility" 0;
If you include this command in your script, it will perform the exact same action as you just did through the user interface.
string $nodes[] = `ls -selection`;
Because the visibility attribute is part of the shape node, you must first obtain the shape node from the transform node. Use the listRelatives command. See How can I get the name of a (selected) shape node.
The final script is as follows:
{ //Lists the transform nodes of all selected objects string $nodes[] = `ls -selection`; for ($node in $nodes) { //Loop through each object and obtain its shape node string $shapes[] = `listRelatives -shapes $node`; //Set the visibility attribute of each shape node to 0 //The shape node is saved to the 1st (or 0th) element of the $shape array setAttr ($shapes[0] + ".visibility") (0); } }
You can save your custom scripts to the shelf if you plan to run them often.
In the Script Editor, select the lines of the script that you want to add, and middle-drag the selection to the shelf.
A dialog appears asking you to select the language of your script.
After selecting the language, an icon representing your custom script is now added to the Shelf.
You can use this editor to customize your new Shelf addition. For example, customize the icon in the Shelves tab, or modify your command in the Command tab.
In addition to performing an action through the Maya interface and examining the result that is printed in the top pane of the Script Editor, you can also query the names of attributes in the following ways:
For example, enter the following in the Script Editor:
listAttr polySphere1
The following result is printed in the top pane:
// Result: message caching isHistoricallyInteresting nodeState binMembership frozen output axis axisX axisY axisZ paramWarn uvSetName radius subdivisionsAxis subdivisionsHeight texture createUVs //
polysphere1 is the history node of the polygon, and listAttr returns the attributes that were used to create the sphere; for example: subdivisions, radius, and so forth.
The following command returns a lot more attributes, such as rotateX, scaleX, and so forth:
listAttr pSphere1
pSphere1 is the transform node of the polygon. This is the node that contains the attributes used to transform an object.
If listAttr returns too many attributes, making the text difficult to read, you can also find the attributes in the nodes documentation.
In the Technical Documentation, Nodes section, navigate to transform, for example, to access the transform node documentation, or geometryShape to access the shape node documentation. On this page, you will find the names of the attributes that you can modify in your script.
The node.attributeName is directly added to the Script Editor.
In the Outliner, enable Display > Shapes and Display > Attributes (Channels). As you select an attribute, the selection command is echoed in the Script Editor, allowing you to find out the attribute name. For example:
select -r pSphereShape1.castsShadows ;
Right-click the Outliner and select Attribute Order > Alphabetical, ascend to sort your attributes, making them easier to find.
To get and set attributes, use the getAttr and setAttr commands.
You may want to change the attributes of selected nodes, or all nodes of a specific type, or all nodes in your scene.
Use the ls command and its associated flags to list any of the above and store the results in an array.
For example, to list all nodes:
ls
To list nodes of a specific type, for example, polySphere:
ls -type polySphere
The following example script lists all nodes of type polySphere and then increases each sphere's radius by 2.
{ string $nodes[] = `ls -type polySphere`; for ($node in $nodes) { int $r = `getAttr ($node + ".radius")`; setAttr ($node + ".radius") ($r + 2); } }
To list the transform nodes of all selected objects in the scene:
ls -selection
The following example script scales all objects in the selection list by 2.
{ string $nodes[] = `ls -selection`; for ($node in $nodes) { int $sX = `getAttr ($node + ".scaleX")`; int $sY = `getAttr ($node + ".scaleY")`; int $sZ = `getAttr ($node + ".scaleZ")`; setAttr ($node + ".scaleX") ($sX * 2); setAttr ($node + ".scaleY") ($sY * 2); setAttr ($node + ".scaleZ") ($sZ * 2); } }