Objects
MEL is most commonly used to create and edit objects. This section covers the variety of commands devoted to objects. As mentioned earlier, all Maya objects are actually Dependency Graph nodes, so the process of creating and manipulating objects really involves creating and manipulating nodes. Fortunately you don't have to know the exact details of each object or node in order to use it. There are a lot of MEL commands designed specifically to access objects without your knowing their inner...
Operator Precedence
It is very important to understand the precedence of a given operator. Not knowing the order in which an expression will be evaluated can cause obscure bugs. The code looks right and runs just fine, but the end result is wrong. The cause is often an incorrect assumption about the order in which operators are evaluated. Take the following piece of code From mathematics you know that the multiplication should be evaluated first then the addition, resulting in 20. If the multiplication didn't have...
Global And Local
Variables a and b are considered local to their particular blocks. Being local means that they are accessible only within their block and any inner blocks they may have defined. Sometimes you'll want to have a variable that you can share with other blocks defined outside. For example, you may want to store the name of the current user and make this accessible to all your scripts. A special scope has been created for this very purpose, the global scope. Once a variable is defined as global, it...
Determining Types
If you are unsure about the type of a given variable, procedure, or other MEL statement, use the whatls command. In this example, the whatls command is used to determine what a is. This example shows that arrays of variables can also be identified. objs - Is whatls Sobjs The whatls command can be used to determine if a function call is to a built-in command. It can also be used to determine whether the statement is a procedure and where the source code for the procedure is located. If you...
Maya Programming
An Extensive Guide to MEL and the Cm AP The Morgan Kaufmann Series in Computer Graphics and Geometric Modeling Series Editor Brian A. Barsky, University of California, Berkeley Complete Maya Programming Curves and Surfaces in Geometric Modeling An Extensive Guide to MEL and the C API Theory and Algorithms Real-Time Shader Programming Ron Fosner MEL Scripting for Maya Animators Mark R. Wilkins and Chris Kazmier Texturing amp Modeling A Procedural Approach, Third Edition David S. Ebert, F. Kenton...
Attribute Information
What are all the available attributes of a given node The 1 i stAttr command can be used to get a complete list of a node's attributes. The listAttr command returns an array of strings string that hold the attribute names. The following example shows you how to iterate over the individual names and print them out string attrs - listAttr nurbsSpherel print nAttributes fori attr in Sattrs print n attr It is also possible to use filters to restrict the listing to particular types of attributes. To...
Command Arguments
In the previous example, the sphere command was executed. This created a sphere object with a default size. It is possible to define, in advance, what size you would like the sphere to be. In order to do this, you simply need to include a specification for the sphere's radius when you call the sphere command. To create a sphere with a radius of two, you would use the following Following the sphere command is the radius argument -radius 2. This argument includes which parameter is to be set and...
Maya Architecture
If you had experience using another 3D package before using Maya, you'll recall that you had to make a mental switch from what you were accustomed to with the other package to how Maya works. While most 3D packages ultimately attempt to accomplish the same overall tasks, the approach they take can be quite different. The steps that you must perform in order to complete a particular operation are often unique to a given package and therefore impose a certain predefined structure to your...
Logical Operators
Sometimes you'll want to compare more than two variables in combination and then perform some action. For example float Sresult - 2.9 float worl dRecord - 2.87 float firstPlace - 2.9 float personalBest - 2.8 if Sresult ifirstPlace amp amp result gt SworldRecord print Winner and beat world record if Sresult lt ifirstPlace amp amp Sresult gt SpersonalBest print Lost race but beat personal best Using logical operators, you can combine multiple comparisons and then perform some action. The complete...
Pushpull Approach
As mentioned earlier, the DG operates, at least in a conceptual sense, like a data flow model. It would appear that data is fed into one end of the machine and some processed data comes out the other. While this mental model makes it easier to understand how all the nodes could be connected to create a machine capable of processing data, the actual implementation of the DG is more subtle. The DG is, in fact, based on a push-pull model. This model defines that certain information can be pushed...
Initialization Of Globals
It is important to understand how initialization of a global variable is done. Like all variables, unless you explicitly initialize them, they take the default value. The following variable, S depth, since it is an i nt, is initialized to the default 0 An explicit value for the variable could also be specified. It is always preferable explicitly to initialize your variables. This makes it immediately clear what value it should have. It is important to understand that a global variable is...
Fundamental Maya Concepts
2.2.1 3D Application Design 11 Past Approaches 11 Maya Approach 12 2.2.3 Visualizing the Dependency Graph 15 2.2.7 Compute Function 21 Dependent Attributes 22 Time 25 2.2.9 DAG Nodes 29 Transforms and Shapes 30 Parenting 32 DAG Paths 34 The Underworld 35 Instances 37 2.2.10 Dependency Graph Updating 40 Push-Pull Approach 40 Updating in Practice 44 Keyframe Animation Updating 48 3.2 The MEL Programming Language 56 3.2.1 Commands 56 Issuing Commands 56 Command Arguments 61 Command Help 62 Command...
Crossplatform Portability
Given Maya's widespread deployment on multiple platforms, it is important to decide whether portability is an important consideration. If you need to develop for only one platform, then this becomes less of an issue. However, with the increasingly widespread use of mixed platforms for both data processing and rendering, it may be prudent to consider the potential consequences of your decision now. Since MEL is a scripting language, it has been designed to be easily portable to other platforms....
Updating In Practice
Now look specifically at how Maya has implemented this push-pull approach. This section takes all the knowledge gained in the previous sections and provides a complete explanation of how the DG works internally. The DG presented earlier is shown in Figure 2.30. Maya associates with each attribute a flag that works exactly like the needsUpdating flag discussed in the previous section. Maya refers to this flag as the dirty bit. The dirty bit is set when an attribute's value is old and needs...
The Mel Programming Language
This section provides an introduction to the programming language, as well as covering, in detail, the language's syntax and constructs. When a MEL command is executed, what actually is happening is that one of Maya's C functions is being called. When you created the sphere from the user interface, you were indirectly calling Maya's sphere command, which actually created the sphere object. In the C API chapter, you'll learn how to create your own commands, but for the moment you focus on...
Displaying Warnings And Errors
To signal when a warning or error occurs, use the warning or error commands, respectively. As a general convention, warning is used when a nonfatal error is encountered and the script can continue execution. When a fatal error has occurred and the script can't continue execution, and therefore must be terminated, error is used. Both these commands print a message to Maya's command window. When Maya is running in batch mode, both types of messages are printed to standard error. This is typically...
Custom Script Directories
If you'd like to have your scripts stored in a custom directory, then you simply need to set the MAYA_SCRIPTS_PATH environment variable. While the concept of environment variables exists on all platforms, the exact implementation and methods for using them often differs. If, for example, you had your scripts in the c myScripts directory, then the environment variable can be added to the script path as follows set MAYA_SCRI PTS_PATH- MAYA_SCRI PTS_PATH c myScripts When Maya looks for a script,...
Transformation Matrices
While you interact with the transform by changing its individual components scale, translation, rotation , the final result is a transformation matrix. This matrix encodes all these operations into a single structure. Transformation matrices have four rows and four columns 4 x 4. To transform a point, postmultiply it by the matrix. The transform node holds the current transformation matrix. You can ask that Maya give you different types of matrices depending on which space you want to work in....
Showing Line Numbers
Unless you are the world's luckiest programmer, not all your scripts will compile and execute the first time without error. The most common errors are syntax errors. These are errors in which the text you've typed doesn't make sense to the interpreter, so it displays an error, then stops. The steps to locate and correct syntax errors are now covered. 1. Click on the Edit Script button. 2. Remove the semicolon from the sphere command so the file now appears as follows This has clearly introduced...
Default Script Directories
Assuming you've created a script file, it needs to be placed in a directory where Maya can find it. Maya looks for user-defined scripts in a few different places. The root path that Maya uses to begin looking for your scripts is based on the user's login name. Under Unix this is just the username, while under Windows it is the name used to log in with. In the following example, the user is the directory in which the user settings are stored. The disk_letter denotes the letter of the hard disk...
INTRODUCTION Wux
The Maya Embedded Language MEL is Maya's most easily accessible programming interface. Without knowing it, you have been using MEL from the very moment you opened Maya. Selecting an object or displaying a dialog box is the direct result of a MEL command being executed. In fact, the entire Maya graphical user interface GUI is controlled by MEL. Almost all of Maya's functionality can be accessed through MEL. As you move through this chapter, you'll get a much better idea of how pervasive MEL is...
Keyframe Animation Updating
One of the interesting side effects of the push-pull model is that it allows you easily to build an interactive keyframe animation system. A keyframe animation system is one in which the animation of the objects is defined by a series of animation keys defined at different points in time. When no key exists for the given time, a new value is derived by interpolating from the key before and after the current time. Interestingly enough, it is the side effect of using dirty bits that allows you to...



