PDA

View Full Version : Mel vs Python?


Omita
12-27-2010, 05:16 PM
I've been away from Maya for some time now. I coded Maya tools for years using Mel. A lot of the game houses in Seattle have been using Mel because they still use Maya 8 or because they didn't want to embrace Python with such a large number of Maya uses only knowing how to use Mel...

Eitherway, I am starting a new project for a different company and I didn't know we should start in Python. I like the idea of having a actual OOP framework for the tools instead of tons of Procedural code.

If Python is the way to go what IDE to people recommend. Are there any tools like MelStudio Pro but for Python?

Thanks in advance.
-i

haggi
12-27-2010, 07:14 PM
Go for python. And if you need non time critical scripts, you can use pymel. Especially for complex projects python is a huge timesaver. The same functionality will need often half the number of lines in python. And if you need some deeper influence you can use the python API interface. It is quite easy to create your own nodes or commands.
We use eclipse for python which works fine.

sacslacker
12-27-2010, 07:28 PM
I'd toss in a vote for Wings IDE for Python but Eclipse is free and good too.

PyMel is integrated into 2011 too. I can't see a reason not to use Python. Object Oriented code is quite the bonus.

ginodauri
12-28-2010, 08:06 AM
Python is bettter language than mel.

Even for simplest tasks python is cleaner and easier to wrtite.

About ide.
You can get command completion with pymel.You can use python "old way" because pymel import all maya commands.
But syntax highlighting is not supported.

If you don't write some very advanced stuff maybe maya 2011 script editor is best choice.

Eclipse and komodo are great , but find komodo to be better.

pearblossom
12-28-2010, 03:17 PM
Python is great! Once you switch over, you will not ever want to go back to MEL. Even as a relative coding newbie it saves a lot of time, and you never have to deal with 'tokenize' again.. :)

ewerybody
12-28-2010, 05:30 PM
For some versions there was stringToStringArray (http://download.autodesk.com/us/maya/2009help/Commands/stringToStringArray.html) which made me never deal with tokenize in Mel.

I still want to honor Mel for its early benefits.:bowdown:It showed me that almost anything is possible within Maya. Which was quite an enlightenment! But now rest in peace Mel. It was (almost always) a pleasure.

btw: I avoid pymmel and use Notepad++ (http://notepad-plus-plus.org/) and some Autohotkey as "IDE" :D

ganzo
12-28-2010, 06:41 PM
This python vs mel issue has been discussed plenty of times...but I will give my pennies on it.

First you have to understand that the python implementation as far as I'm concerned is really just a wrapper for most mel commands. Also, if you know python way before all these wrapper modules started to come out, you will notice that most of its syntax structure is focused on parsing text and most of the methods are database oriented. That is why it mostly started out a data management language...it was great for database programming. MEL on the other hand has been there way back....when there were no tools...all was done through mel..dont even think it was even called maya back then. So it is very very integrated into the whole thing.

That being said I will mention some of the pros and cons of both:
Python: It is a tabbed language, meaning they got rid of semicolons, brackets and other syntax symbols that mel/c++ use. I wont say this necessarily make it cleaner since many mel/c++ people might disagree, however it is a good language to make quick prototypes. About python in maya, well in my opinion it is way better for interface design and pipeline type of stuff. Also exporting and reading in files it is also a good language since it was built for this.

MEL: I don't have any benchmarks, but with its close c++ syntax structure and the fact that it is deeply embedded to maya..I can bet that it is way faster than using python on things like doing operations on thousands of vertices, matrix calculations etc. That is why it is still preferred over python for these type of things.

So to answer your question.....know both!.....depending on the task you will choose the best tool for the job.

NaughtyNathan
12-28-2010, 07:18 PM
First you have to understand that the python implementation as far as I'm concerned is really just a wrapper for most mel commands. .... MEL: I don't have any benchmarks, but with its close c++ syntax structure and the fact that it is deeply embedded to maya..I can bet that it is way faster than using python on things like doing operations on thousands of vertices, matrix calculations etc. That is why it is still preferred over python for these type of things.

this is slightly erroneous. Most or all of Maya's "commands" are written in C++ and reside inside an internal binary library. MEL is simply a wrapper to these C++ functions and python is simply a different wrapper to the same internal functions.
In theory there should be no difference in performance between the same single MAYA command in MEL or in python, but in practice, some operations will be slower in MEL and some will be slower in python simply because of the way they are attached at a very low level. However, I did some tests on this (which you can probably still find here if you search) and I had to repeat the single operation over a million times to even register a time difference. However, in the majority of cases where you are working on larger data structures python will likely be quicker every time (not to mention FAR easier to manage that data).

I know both MEL and python pretty well and I still write all my code inside Maya (shelf buttons, hotkeys, few line script-editor) in MEL. I find it far cleaner and easier on the eye than python (in maya!). However, if I am writing any real script or tool that requires any kind of data handling, external process, or API function I use python.

As far as Maya programming goes, I find python a real pain in the ass for ELF UI (hate having no manual indentation) but almost everything else about it is a dream compared to clunky MEL.

:nathaN

haggi
12-28-2010, 10:33 PM
I agree, it seems that ganzo is confused with pymel and maya python. Pymel started as a wrapper for maya python and is often several times slower than maya python. But meanwhile they communicate much more directly with maya. e.g. you can do something like this (im maya2011):

import pymel.core as pm
obj = ls("polyCube1")[0]
obj.rename("newName")
obj.translate.get()

previously the renaming in this form invalided the obj because it then pointed to an object with a old name. In mel its the same.

For maya2011 I switched for interfaces completly to python. With python2.6 you have an great indentation like:

def clickButton(value):
print "Value", value

import pymel.core as pm
with pm.window():
with pm.rowColumnLayout():
pm.button(label="First button", c=pm.Callback(clickButton, "klicked"))


Here you can see how the with statement works. And additionaly you can use the Callback() class to simplify the calling of callbacks. Really cool and much more efficient then in mel.

With the pymel.ui classes you can even build subclasses and implement a complete functionality into one class with the usage of instance variables and methods.

But in some cases I agree. e.g. the uiTemplates are a horror with python. There all calls are converted into mel commands which then call python scripts. Not very conveniant. This way, a lot of object oriented features doesnt work. The same for render scripts if you implement your own renderer. These scripts which are called if you hit the render button or the ipr button are pure mel scripts and are complicated to control with python.

And there is another thing that was easier with mel. You simple put your mel script in your script path and it worked. Now if you use python the pythonic way, you often have to import modules, and you have to know which modules contain which classes and methods. But this way you can work much more structured. e.g. you can have script with the same name in several levels.

Joviex
12-29-2010, 05:53 AM
I agree, it seems that ganzo is confused with pymel and maya python. Pymel started as a wrapper for maya python and is often several times slower than maya python.


Chad et. al are working on it. It would help if people would send requests to AD to help support migrating/intergrating PyMEL deeper into the API.

The core of the issue is translation. PyMEL has to translate the API objects into strings and back again because it is written as a wrapper. If it was a first class citizen =)

ALTHOUGH, here is some code to show you that PyMEL is not really lagging, nor is MEL completely lagging, but in the end, depending on what you are doing (i.e. iterating over thousands of vertices) it may make a difference:


import pymel.core as pm
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as OpenMaya

def MayaAPI(obj):
list = OpenMaya.MSelectionList()
list.add(obj.longName())
node = OpenMaya.MObject()
list.getDependNode(0, node)
nodeFn = OpenMaya.MFnDependencyNode(node)
x = nodeFn.attributeCount()
for i in range(0, x):
attr = nodeFn.attribute(i)

def PyMELAPI(obj):
pm.listAttr(obj.longName())

def MayaCmds(obj):
cmds.listAttr(obj.longName())

import time
obj = pm.ls(sl=1)[0]

# MAYA API SPEED
start = time.time()
for i in range(0,2000):
MayaAPI(obj)
print time.time()-start

# MAYA CMDS SPEED
start = time.time()
for i in range(0,2000):
MayaCmds(obj)
print time.time()-start

# PYMEL SPEED
start = time.time()
for i in range(0,2000):
PyMELAPI(obj)
print time.time()-start

# MEL SPEED
start = time.time()
for i in range(0,2000):
mel.eval('listAttr %s' % obj.longName() )
print time.time()-start

Boilerplate I use to anecdotally test new PyMEL/Maya versions.


But in some cases I agree. e.g. the uiTemplates are a horror with python. There all calls are converted into mel commands which then call python scripts. Not very conveniant. This way, a lot of object oriented features doesnt work.

That is why we don't use the templates, nor any ELF stuff no mas.

PyQt4 + designer = done in 5 minutes, callbacks galore, deeper/richer interfaces, pluggable/reusable components, etc, etc...

I still have die hard ELF fans at work, I do not expect them to go away anytime soon, but after a decade coding MEL and six in python and QT, I fail to understand the benefit of doing it in MEL. We have been using PyQt+Python since Maya 2008.

Albiet a little screwy in 2011 now that they have incorporated it, BUT, that just means we are technically stuck at version 4.7.1 of QT for 2011, but can still use 4.8+ for anything previous.


And there is another thing that was easier with mel. You simple put your mel script in your script path and it worked. Now if you use python the pythonic way, you often have to import modules....

When people ask if I can show them how to properly "script" for Maya... sure, namespaces 101.

When I first started working my current position they had 200+ scripts in 15+ directories and about 100+ in a root directory. You want to talk about ugly?

You know how many times a day I was doing whatIs just to find the collisions?

Namespaces are simply good coding standards =p

CaptainSam
01-03-2011, 12:36 PM
btw: I avoid pymmel and use Notepad++ (http://notepad-plus-plus.org/) and some Autohotkey as "IDE" :D

You really really should use PyMel, except for stuff that involves tens of thousands of nodes, where MayaPy will be signifcantly faster. Even though PyMel is slower, the speed of developing in PyMel versus MayaPy far outweighs the (mostly) insignficant speed difference.

Theres an enormous difference between just coding in a text editor (or the Maya script editor) and with a proper IDe such as Eclipse or WingIDE. Rather than having to put print statements all over the place to try to find a bug, you can do stuff like stepping through the code, setting breakpoints, watching variables, etc. You'll literally save days of work once you write anything lager than a few hundred lines

Download the 30 days WingDB trial and try using it with Maya:
http://www.wingware.com/doc/howtos/maya

ewerybody
01-05-2011, 12:47 PM
You really really should use PyMel, except for stuff that involves tens of thousands of nodes, where MayaPy will be signifcantly faster. Even though PyMel is slower, the speed of developing in PyMel versus MayaPy far outweighs the (mostly) insignficant speed difference.[/url]Nahh I should rather keep avoiding PyMmel and do stuff on my own. Surely PyMmel offers you a lot of stuff out of the box for the easily convinced man... I'm obviously not that kind of man ;]
And as it turns out stuff is not always necessary and bloats the entire thing on the backend. On the other hand I still have to code a lot for Maya2009 and I surely don't go and install PyMmel on every machine in the company.

PyMmel inspires me a lot! But Ok I actually find [url="http://packages.python.org/MRV/"]MRV (http://www.wingware.com/doc/howtos/maya) much more impressive! Both are comprehensive packages. Just like Mr Hamish McKenzie I tend to build my own package of tools.. This way you learn the most :]

@wingDB: I'd love to give Eclipse a try first.. why bother working with a commercial IDE.. IF the OS one is just as good. That is to be determined first :D

CGTalk Moderation
01-05-2011, 12:47 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.