Recent Posts



MSFBA Chapter 0: getting started - the logic of scripting/programing.

0. How to approach these tutorials

For the most part of my tutorial, I will try to explain different programming concepts in laymen terms as well as using real life scenarios as example to make these concepts easier to digest. Of course, by doing so, it's hard not to oversimplify information sometime. But I'm a greedy dood who want the best of both world therefore I will also include the full and much more technical explanation on the concept encapsulated like this.


some lengthy technical explanation here


These technical areas have extra and more in depth explanations for artists who is interested in digging deeper in the technical rabbit hole. Otherwise, can be safely ignored by more casual learners.

At the end of each tutorial, there are few exercises and scripts that you can download and try them out on your own. It doesn't matter how much you read, only through constant practice that you truly learn how to code.

I also highly encourage you to learn actively. Try out everything you learn to double confirm that it works. I'll try my best to make sure my tutorial as accurate as possible but I simply don't know what I don't know. There will be undoubtedly on some occasion I get the concept wrong, so please don't be hesitate to let me know so I can fix it, making this a better tutorial.

Alright, with all that rambling, enjoy and happy coding!

1. MEL vs Python

Within Maya environment, there are three ways you can code with, MEL, Python and C++ API. C++ API is way out of the scope of this tutorial series so we are going to pretend it doesn't exist here. So let's get down to just MEL and Python.

One of the question students often give me is should I start with Python or MEL? can I ignore MEL if I can code with Python?

Well, without getting into too much detail, my answer would be both are beneficial; even though they, most of the time, accomplish the same thing. This might sound a bit paradoxical but let me give you a little bit of historical background.

Initially, Maya give you MEL - Maya Embedded Language, a scripting language that ONLY works within Maya environment allowing artists to write tools and expand Maya capabilities.

MEL works just fine until one day, Python is introduced to Maya. Python is a much more robust and versatile scripting language that exist outside Maya. You might have heard that people can develop games, apps, webs or even some powerful scientific tools with Python. So how does this giant of scripting language fit into Maya? How can Maya understand these Python command even though Python developers certainly don't have Maya in mind when they created Python? Is this some kind of technical trickery again? No, the answer is much more mundane than you thought. What the good people at Autodesk did to incorporate Python into Maya is simply convert all MEL commands into Python commands, save it in a library (a virtual one, of course), and have Python access into it. In a nutshell, when you code with Python inside Maya, you are coding in MEL with Pythonic syntax.

So what is the benefit of Python if they just do the same thing as MEL? Again, It's hard to list all the benefit without going too deep into the subject. For now let just say its wayyyyyy more convenient to script in Python. To be honest, I rarely code any MEL in the past few years, except for teaching purposes. So yes, you can totally ignore MEL if you just want to be able to do practical coding, you can go straight for Python. However, with that said, I still highly recommend you to start out with MEL first as it is native to Maya, and certainly will teach you a lot about how Maya works under the hood. Another advantage is that every tools you use in the Maya user interface are all written with MEL, which I will show you where to find and read those in later tutorial. This provides a massive and excellent study case, even experts can benefit from patiently go through these "give away" codes. Also , if you plan to take on the heavyweight beast C++ API later, MEL is a excellent base to have since MEL is derived from C++, they share almost similar structure and syntax.

So bottom line is:

1. If you can code in Python, there's no need to learn MEL


In this tutorial series, I will attempt to do something I have not seen before - attempting to cover both MEL and Python at the same time. My focus is more on the programming concept. By showing you both MEL and Python version of the same concept, I hope that programming becomes even less intimidating to you( read on to know why ). Of course, you can either read just MEL, Python or both sections. However, I would recommend you start with one language first, do it to a certain level then you can switch to another one to avoid syntax confusion.

2.Programming demystify

If you have never gone to a programming class, programming can certainly looks like some kind of black magic to you. bolstered by hundred of movies which portray hackers as some genius that can blitz out lengthy, incomprehensible codes to the computer and voila, NASA is hacked! All of that creates a mental barriers that programming is some kind of mad skill only intellectual genius can do.

In reality, programming is nothing more than giving your computer step by step instruction to accomplish a task. Giving clear, precise instructions is what programming all about.

Imagine this scenario, you have a robot named Mike. he can take in instructions and do thing lightning fast. However, Mike isn't very smart and only take instruction literally without the finesse of human interpretation. For example, you give the instruction:

- eat a bag of chips

Mike will literally take the bag of chips and swallow it whole! Not a very good idea if you care for Mike. Knowing Mike only takes literal command, your instructions should have been more detail like this:

- take a bag of chips

- open a bag of chips

- for each chip in the bag:

- take and put it in your mouth

- Chew it

- Swallow it

Now believe it or not, the instruction above is a legit program! It's just not written in any real programming language. However, the same logic apply to all programming language. what programming language is, is a fixed format that allow you to write instructions for the computer in a clear and efficient way. Here's what the instructions above look like if I write it in MEL:

in Python it probably looks like this:

Instantly, these simple instruction looks a lot more intimidating. All of these weird esoteric syntax will be covered later so don't worry for now. All you need to do is take a quick look at these code, compare to the original plain English instructions and see that, only the syntax make it looks scary. Essentially, all three version of instructions express the same thing.

Of course if you type these code in Maya script editor, it won't work. Because, these are not real commands. I made those up in order to help me demonstrate a point: breaking down a complex task into simple and clear instructions is the heart of programming. In subsequent chapter, when we go into real programming stuff, you will see the same logic as above being applied over and over again, only with actual functioning command.

So what is the benefit of learning this? Well, in my opinion, this is the most important part when you start learning programming - think like a programmer, learn to break down a complex task. Once you get used to this way of thinking, programming will become a lot easier. So let's start giving instruction to your computer!

* Technically, Programming and Scripting is two different thing, at least on theoretical level. For the purpose of this tutorial series which is to introduce Scripting to beginners, we will consider Programming and Scripting one and the same. *