Recent Posts



MSFBA Chapter 1: Command and Syntax - just like vocabulary and grammar.

1. Command

1.1 What is a command?

Command is basically the vocabulary of a programming language. It is a simple, direct instruction with a particular function. For example, in Maya script editor type in and run


lo and behold, a sphere appears.

As you might have guessed, polySphere command function is to create a sphere. And if you are asking yourself at this moment, is this the same as clicking the button to make a sphere; yes, they are the same!

For every button you click in the Maya user interface, there is one or more MEL command being triggered behind the scene. Therefore, there is no different between using Maya UI vs running the command directly within the Maya Script Editor.

Combine this and the logic presented in the previous chapter, you might have already get how can we use scripting to boost productivity. Essentially, scripting allow you to string a bunch of puny, simple, singular commands into a much more complex function that can be triggered at once. 

For example, if I copy paste polySphere command 10 times, save it as a button and I have a button that can generate 10 spheres at once.

Of course, that button is kinda low on practical value for now but it does accomplish something that you don't have with default Maya UI. (there will be better way to repeat the same commands over and over again than copy paste too, we will cover that later).

1.2 How do I know which command to use?

Alright, so it's cool to know that every button trigger a MEL command but how do we know what command being triggered ? Do we have to memorize some gigantic manuscript on MEL command ? Luckily, we don't! Maya have already told us what command being triggered when we press a certain button. Click on the button to create a sphere and take a look at your script editor. You will see as the sphere appear, a new line of code appear immediately in the history section.

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;

Now, if you copy this and paste to your script editor and run it, a sphere will appear as expected.

** Try this out **

Please pause the tutorial, and try that out in Maya. Try to click on a few button that you used to use, pay attention to the script editor and see how many command you can find out with the method presented above. Perhaps try to find out what is a MEL command to make a cube, make a circle, make a light or move an object around...



- one trick to remember the command is remember the naming convention for command. It start with lower case letter and use a upper case letter to separate words like this:

polySphere, setAttr, shadingNode,textFieldButtonGrp...

- if the command is type correctly, its color should turn into cyan instead of white.


Echo all commands

If you have done the *try this out* session long enough, you might realize that certain thing you do in Maya UI doesn't give you back a corresponding command in the script editor. For example, if you hit the "+" sign on your key board, you see the transformation handle grow bigger and hit "-" to make it smaller. These action don't give you back a corresponding MEL command.

It turns out that there are several things you do via Maya UI have their corresponding MEL command hidden away from you. Why? you might ask. To be honest, I have no idea myself. There might be certain logic to what command needed to be hidden from you and what not, but for our practical purposes, it doesn't matter.

There is an option to make Maya tell you every single shady thing it does behind the scene, basically a Maya "confession" option. It's called Echo all commands

When you turn it on, the history session of script editor will show you every MEL commands and procedures corresponding to each action you take in the UI. While these hidden procedures does look intimidating and not easy to understand even for experts, they provide extra resource for researching commands.


1.3 What are those extra lengthy thing behind the command ?

Now the next question is, what is that esoteric code right after the cyan colored command

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;

what does this "-r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1" mean ?

These are called "flags". Flags allow you to modify various properties of a command. A flag start with a dash "-" follow by a flag name and usually a value. For example:

polySphere -radius 10;

make a bigger sphere than

polySphere -radius 2;

-radius is a flag design to modify the polySphere command radius. And you can stack a lot of flag together in a command to have more control over it.

Do I remember all of those flags for every command I used? No, I don't as there is no need to stress my brain out on something I can always check online. 

If you hit F1 while inside Maya, it will bring you to the official documentation for the current Maya version of yours. Navigate to technical documentation, you will find the entire library of MEL command. Click on one command you interested in knowing more and that is where you find all the flags you can use within that command.

For now, the exact detail of how to read this table is hard to explained without explaining data type concept first. So, we will return on this after the next chapter in this tutorial series. For now all you need to understand is these flags listed in the table can be used to give you more control over your command. 

Let's take a look back at our cryptic

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;

and try to decipher what it means. Have your polySphere flags list open and let's do it together.

polySphere is a command to make a sphere - easy!

-r 1 - If you check your table, this flag allow you to set a radius to a value, in this case 1 is the length of the radius.

-sx 20 - This tell the command to make 20 subdivision along the x axis of the sphere

-sy 20 - This tell the command to make 20 subdivision along the y axis of the sphere

 -ax 0 1 0 - This set the direction of the sphere axis to align with world y axis. This is the most cryptic part of the command if you have not familiar with vector data type yet. So for now, it's OK if you don't fully understand this flag.  We will return later.

-cuv 2 - this allow you to choose a type of default UV you want on the sphere.

-ch 1 - this is to keep the history after the sphere is created. This is an on and off switch. 1 mean to turn on this option and 0 mean to turn off this option. 

So to sum up in plain English, this command will do the following:

- make a sphere with the radius of 1, 20 subdivision along the x and y axis, axis point y along the world y axis, with default UV and keep the history on.


- There are two ways you can type in a flag name, long name and short name. -r is the same as -radius. You can see that in the flags table of every command. Right after the long name of a flag, a short name is also shown in bracket.

- I would reccomend you almost always stick to long name instead of short name. It takes you longer to type but will save you a lot of time later when you troubleshoot your script.

You can also play around with different value to see have a firmer understanding of these flags and of course you can try out different flags on different commands too. The more you experiment here, the better you will understand these flags. 

In conclusion, a command is a direct instruction with a specific function you send to Maya. Flags are properties you can change within a command to have more control over it. 

As you have seen so far, a command is not hard to understand but how it was written make it looks alien to non-programmer and that is where Syntax come in.

2. Syntax

Given that it took me 3 lengthy session to just explain the very basic of command, you would expect something even longer here in this session. Sadly, there is not much to understand about syntax but more like following the format.

Syntax is just a strict format you have to follow in order for the computer to make sense of your code. for example in MEL as you have seen so far, every command must end with ";". a flag must start with "-" which is not applicable in Python as Python have their own separate rules of syntax.

There is really not much logic in syntax. You just have to remember and follow it. That's why syntax error is among the most annoying error to me personally. You happily write a code with perfect logic and when you run it, it won't work because you forget to put a ";" somewhere in your script. Yes, you do have to patiently go through your script again to hunts for these syntax mistake and fix it. #syntaxNazi

So the only way I could think of to learn syntax is we learn as we go along, creating scripts in subsequent chapters. See ya there!