|
The simplest thing you can find in MEL are the commands. Maya is build up by tons of commands. Every time you do something in Maya at least one commands is executed, mostly several. To figure out which commands Maya executes you should turn on "echo all commands" in the script editor. (Script --> Echo all commands). Your number one sources when it comes to MEL are the scriptEditor and the help files. These are awesome. Try creating a polygon sphere while you pay attention to the history in the script editor. What you will see when it is created is:
polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 1;
It returned a bunch of code here, but the essence is "polySphere". All the other things here are flags and values. You see a command is built up like this:
command [flags] [name]
The -r flag is the radius with a value 1 here and -sx and -sy are divisions in those axes with values of 20. Notice that the command polySphere does not have a name. If you look in the helpfiles for polySphere you see that this command actually does not have a name. ( you can use the flag "name" to name the sphere, but when I say name here I mean the ID at the end [name] )If you are insecure, check the help files. They are extremely helpful!
If we look at the window command the helpfiles show us this:
window [flags] [windowName]
There are also different modes for the flags. "Create" ( which is default ) , "Edit", "Query" and "Multiple use of flag". I'm going to go through some of them in the following example.
If we take a look at the command window we can add many flags, I'll use -width and -height as an example.
//We're going to create a window with a width of 100 and a height of 200.
window -width 100 -height 200 myWindow;
showWindow myWindow;
Now, what we did was create a window with a width of 100 and a height of 200. We also gave the window a name, "myWindow". This will ID the window later like when we want to open it ("showWindow myWindow"). You see, the window command doesn't show us the window, it just creates it in the background. To actually be able to see it, we have to tell Maya that we want to see it by using the command showWindow. So showWindow is another command you can look up in the help Files.
If we look at the command window again and check out the flags we see that there's a flag called
"-widthHeight". You can also see that inside the parentheses the short form for -withHeight is -wh. This means that we can choose to write the long form or the short form. There are disagreements whether you should use short or long. Personally I like to use short ones because the code will be shorter. On the other hand the long name will be more explanatory. When I edit scripts I tend to jump back and forth between Maya and the help files anyway...
Let's take another look at the window command:
//I want to know the width and the height of a window.
window -q -wh myWindow;
If you look at the history in the scriptEditor you get "result: 100 200". Of course we knew that, but you can use this for any window. If we scaled the window the result would have been different. When we want to gather information from a layout or other UI elements we have to put it in "query"- mode. Say we wanted to get the label of a button we'd write:
button -q -l myButton;
Now, let's try and edit the window size. If you're paying attention you'll know that we have to put the layout/element in edit - mode. The code would look like this:
window -e -wh 150 100 myWindow;
Now we edited the size to a new value. Keep the window open and change the values. You can see the window-size change realtime. |