Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use a MEL command
MEL commands are used to perform many tasks within Maya. There are numerous ways to enter MEL commands in the Maya interface. These include the command shell, the command line, and the Script Editor.
Master it
Create a polygon cube using the command shell. Create a NURBS cone using the command line. Create a polygonSphere using the Script Editor.
Solution
Open the command shell, and type polyCube. In the command line, type cone. In the work area of the Script Editor, type polySphere.
Use MEL scripting techniques
Many basic MEL techniques can be used to reduce the number of repetitive tasks performed during a Maya session. Using commands, conditional statements, and loops, you can create simple scripts that make working in Maya faster and more efficient.
Master it
Write a more efficient version of the mySpriteScript file that automatically selects all the nParticle objects in a scene without the need for a conditional statement to test the type of the selected nodes.
Solution
In the Script Editor, choose History Echo All Commands. In a scene that contains nParticles, choose Edit
Select All By Type
nParticles. Observe the text in the history section of the Script Editor. The line that reads select -r `listTransforms "-type nParticle"`; can be used in the script to automatically select all the nParticles in the scene, which means the conditional statement that tests the selection type is no longer needed. Edit the first few lines of mySpriteScript.mel to include the listTransforms command; then remove the conditional statement from the script. For an example of this alternate version, look at the mySpriteScript_v02.mel script in the chapter17\mel folder on the DVD.
Create a procedure
Procedures are sections of code that can be called upon at any time within a script. Procedures can help make longer scripts more efficient by eliminating the need to repeat sections of code.
Master it
Write a procedure that adds an expression to selected objects that use the noise function to randomly scale objects over time.
Solution
Edit the shakeMeProc.mel file. Replace the text translateX=rand(−1,1); with scaleX=noise(time);. Repeat this for TranslateY and TranslateZ.
Use the Python scripting interface
Python can be used within the Script Editor to execute Python commands or to execute MEL commands within a Python script. The Maya commands must be imported at the start of Python script if you want to incorporate MEL into the Python code.
Master it
Use Python to make a NURBS torus.
Solution
Switch the Script Editor tab to Python mode. Import MEL commands by typing maya.cmds. Type maya.cmds.torus() to create the torus using default settings. Flags can be used to specify attributes of the torus. Look up Python commands in the Technical Documentation section of the Maya help files for more information.