Flags are used with commands to modify their execution. Python implements flags as named arguments. Some flags in MEL do not require values. As all named arguments in Python require a value, these flags are given the value True to enable the flag, or False to ignore the flag. When setting multiple named arguments, argument-value pairs are separated by commas within the brackets. Command arguments must appear before named arguments in a command.
cmds.polyCube(width=5)
The width flag allows you to set the width of a cube at creation time.
cmds.polySphere(radius=1, subdivisionsX=4, name="testSphere")
You can use multiple flags to modify the execution of a command by separating the flag-value pairs with a comma. The radius flag sets the radius of the created sphere. The subdivisionsX flag sets the number of subdivisions in X for the sphere.
To use flags with command arguments in Python
cmds.move(2,2,2)
cmds.move(1,2,3)
cmds.move(-1,0,-2,relative=True)
The polygonal cube moves relative to its current position. The relative flag must be placed after the command arguments, as in Python, when passing arguments, named arguments must appear after positional arguments. The command arguments must always be the first arguments of the command.
cmds.move(3,2,1,"testSphere",relative=True)
The name of the object must be passed as a string after the command arguments, but before the flags.
To use flags with multiple arguments in Python
cmds.pointLight(rgb=(1,1,0.5))
The point light command creates a point light at the origin. The rgb flag specifies the color of the light. The rgb flag require three values; red, green and blue.
When flags require multiple values, the values must be packed within Python’s tuple or list data types. Tuples are a method of storing multiple items of homogenous data within a single variable, similar to an array in MEL. The list is similar to the tuple, but supports multiple data types within a single variable. The above command packs the RGB values into a tuple. You could also use a list to achieve a similar effect.
cmds.move(12,15,12)
cmds.pointLight(rgb=[0.2,0.2,1])
Square brackets [ ] indicate lists, and parentheses ( ) indicate tuples.
The values for the rgb flag can be packed into either a list or a tuple and perform the identical operation.
cmds.move(12,15,-5)
The Render View opens and displays the following image.
cmds.select(allDagObjects=True)
cmds.delete()
Using the Maya command select with the allDagObjects flag selects objects that exist physically in the scene such as geometry, IK chains and measure tools. These appear on an internal Maya representation called the DAG. For more information, see DAG.