View Full Version : Professional MEL Practices

01 January 2011, 05:15 AM

I'm new to MEL but not to programming and I was wondering if there were any resources out there that detail what one should and should not do when writing MEL.

I know there are books like this for other languages like Scott Meyers Effective C++, but I'd like to know if there are any equivalent resources out there for MEL.

As an example of what I mean, here's a few practices I've come across while reading other threads on this forum:

-avoid global variables at all cost (there will almost always be a better solution or a more stable work-around to them)

-certain actions such as deleting history get stacked onto the undo queue and when repeated frequently will eat-up exorbitant amounts of RAM (the solution I saw posted was to temporarily turn undo off using the undoInfo command with the -swf flag while the script runs)

Any suggestions or words of advice would be greatly appreciated.


01 January 2011, 09:04 AM
i guess the best practice would be "if you don't have any MEL code already, just start off with Python right away". MEL nowadays is more of a legacy, you can even see people with large MEL codebase migrate to Python (Jason Osipa's facial setup scripts, Zoo toolbox, etc), not to mention those that use Python since Maya 8.5 (me would be one of those).

01 January 2011, 11:19 AM
I agree, as a professional MEL programmer I'd also recommend learning python! :D

Seriously though, knowing MEL is great, and is a big help understanding how Maya works and customizing it, but unless you specifically want to edit Maya's default UI there's very little to warrant learning MEL over python. Python is a far better programming language, and there's pyMel too which is a good combination of the two (best of both worlds with additional bonuses)

If you are dead set on learing MEL I wouldn't worry too much about do's and don'ts until you are familiar with the whole language itself. it's all pretty basic, and fully contained inside Maya so you can't do a whole lot wrong, even if you do use a ton of global vars etc.
Having said that though, my one piece of advice to a beginner would be to never use or rely on selection, always reference the items your commands work upon directly in the command. e.g.

// moronic:
select -r myObject;

// sensible:
delete myObject;This approach is valid for 99% of Maya commands.

01 January 2011, 12:24 AM
Thanks for the advice.

I was approaching the prospect of learning how to program in Maya from my experiences of studying computer science at college. As students, we tend to use the quick and dirty way to make code work for one-off projects, instead of learning the proper practices that lead to stable and reliable code when making large scale projects with a team of programmers for real-world clients. (A tendency which comes back to bite you when you start working on such projects. :surprised (

I wanted to avoid learning bad programming habits in Maya early on, but it makes sense that there are fewer mistakes to be made when scripting in Maya than when coding a stand-alone application for public release. ;) (

For now, it seems as though I should keep dabbling in MEL to get familiar with Maya's innards, while I look into Python and pymel to see which would be the best fit for me...
Thanks again for your guidance.

Also, I'm curious: which programming language do you find yourself using most often nathaN?

01 January 2011, 12:44 AM
You can learn a lot from Rob Bateman (
And Mel Wiki ( and Maya Station ( has a lot of nice examples to learn from.

Plus the user Joojaa has a lot of posts here (and on other forums) that ... suggests ... and eh, ... insinuates a lot of his thoughts on good and bad practice when writing mel. Well worth a search. Also Nathan's posts are very informative. And you can find his old mel script depository through a link on his web site. Not more instructional than beeing examples of good scripting practice, though.

01 January 2011, 10:49 AM
thanks for the plug André! :D but I shudder to think what horrendous coding faux pas I may have made in any of those old scripts... I am usually overly anal when coding anyway, but most of those old scripts were written over 8-9 years ago, and many while I was still getting to grips with Maya/MEL... :)

joojaa is certainly a phenomenon and he definitely knows a lot about Maya at every level, but I find him to have the very slight edge of the incoherrant, rambling madman. ;)

@Jonathan (or is it James..?!?) - I'd say I still mainly use MEL, but it's only by a small margin.. about 60% MEL, 40% Python. I mostly write code in an external editor, but pretty much everything I type into Maya is MEL, and any time I have to write a minor function for someone, or any UI customizing stuff it's nearly always MEL. However, if I'm writing any proper, meaty tools, like ray-intersecting context tools, or complex UIs that do a lot of data processing it's usually python. I also find that a lot of personal stuff I do at home and freelance work is 90% python too.

python is WAY better than MEL, MEL has no space or zero padding features for example (which python does in it's sleep), but the thing is, as I love programming (I see it as a form of puzzle solving, in exactly the same way as say, Sudoku, or Labyrinth, which I find immensely entertaining and satisfying) having to WRITE those functions in MEL is hugely enjoyable and rewarding on a personal level! However, when you are getting paid to make good and efficient code (quickly!) this is not really a consideration (or at least it shouldn't be! ;) ).


01 January 2011, 02:45 PM
Thanks for the info and all your suggestions. It looks like I'll be busy for quite a while :D

@nathaN: James Arlyle is a pseudonym I like to use online (doesn't quite work here since CGSociety displays your real name... oh well) feel free to call me Jon

CGTalk Moderation
01 January 2011, 02:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.