> Object Oriented > Lists & Dictionaries > Access to the API without C++ > Access to a multitude of external modules > create and manipulate xml > plugs into your pipeline > QT
this list from shaun is a very good breakdown of python's advantages over MEL, but i think that for those who haven't messed with python much, it doesn't have a whole lot of meaning, because they don't know what each of these things really means. > I really havn't found a situation where I couldn't just write a mel > script for something I wanted to do over and over for the beginner, it's not necessarily about doing things that you can't do in MEL, it's about doing things 10x faster ( with a little practice of course ) > Object Oriented a simple demo of object-oriented string power: # change the name of the node, preserving references node = 'foo:bar:spangle' buf = node.split(':') buf[-1] = 'newName' newNode = ':'.join( buf ) print newNode 'foo:bar:newName' if you're using pymel, you can really leverage object oriented programming: MEL: string $sel[] = `ls -sl`; string $shapes[] = `listRelatives -s $sel[0]`; string $conn[] = `listConnections -s 1 -d 0 $shapes[0]`; setAttr ( $conn[0] + ".radius") 3; PyMEL: not just faster to write, but also easier to read: selected()[0].getShape().inputs()[0].radius.set(3) > Lists & Dictionaries lists can have any data type in them, including other lists. this is a huge selling point for any MEL programmer, who has been forced to have a separate array for every datatype, or to do hacky things to try to emulate 2D arrays l = [ 'one', 2, 3.0, [ 'node1', 'node2' ] ] l.pop( 0 ) # remove something l.append( 'some more data' ) # add something if you don't think that this will speed up your programming, then anything else i say is a waste dictionaries are even more of an advantage because there's no data structure even close to them in MEL: d = {} d['age'] = 28 d['name'] = 'chad' d['hobbies'] = [ 'running', 'playing soccer' ] d['age'] += 1 # increase the age by a year d['hobbies'].append( 'swimming') # add a hobby to the list > Access to the API without C++ . i'll skip this for now, but the fact that the API and MEL essentially speak the same language provides interesting crossover potential. it also means learning python to write MEL-like code opens the door for API programming > Access to a multitude of external modules not just external modules, but internal ones too. the pickle module is one that i think every python programmer should know. if you need to store some data and get it back somewhere or sometime later exactly as it was, it's the most painless way to do it. #start with our list and dictionary from above import pickle f = open( '/path/to/file', 'wb' ) pickle.dump( (l,d), f, 2 ) #somewhere else, say on another computer, or a week later.... import pickle f = open( '/path/to/file', 'rb' ) l, d = pickle.load(f) # data is exactly as it was print d['name'] # Result: chad i don't have time to cover everything, but let's just say python starts as a way to get more done in less time, and eventually opens the door to a whole new way of programming, with a huge community of resources. as a friend put it: "python takes a week to learn and a lifetime to master". It's true that for very simple things MEL shines, but as soon as you graduate beyond that and attempt even the most slightly sophisticated algorithm, your code will begin to bloat as you struggle against the limitations of the language. to put it another way, python is incredibly scalable and MEL is not. - chad On Feb 1, 2009, at 11:47 AM, matt thorson wrote: > Could you guys give me some practical applications of python in FX? > I keep hearing this but I really havn't found a situation where I > couldn't just write a mel script for something I wanted to do over > and over, or make a GUI of things I use often. > > On Wed, Jan 21, 2009 at 8:48 AM, <sh...@pyrokinesis.co.nz> wrote: > > There are many advantages to using python over mel for maya. > > Object Oriented > Lists & Dictionaries > Access to the API without C++ > Access to a multitude of external modules > create and manipulate xml > plugs into your pipeline > QT > and more... > > Mel still has its place, yet Python is much more robust. If you are > interested in FX you will find that Python is becoming a necessity. > > Once you take Python beyond the basics, you will come to the > conclusion > that with Python you can find more elegant solutions to more complex > problems. > > > > > I think you should look more into MEL if you are interested in > learning > > python for maya. Once you get the basics of python you'll realize > that it > > just wraps around MEL. > > > > I found this book very useful: > > http://www.amazon.com/Learning-Python-3rd-Mark-Lutz/dp/0596513984/ref=sr_1_1?ie=UTF8&s=books&qid=1232524679&sr=1-1 > > > > > > This is the book we got in school. > > http://www.amazon.com/Scripting-Animators-Kaufmann-Computer-Graphics/dp/0120887932/ref=sr_1_1?ie=UTF8&s=books&qid=1232524424&sr=1-1 > > > > > > Chris Maraffi ( former teacher ) wrote this book but it might be > kinda > > outdated. The scripting stuff should still apply but the rig is > wack. > > http://www.amazon.com/MEL-Scripting-Character-Rig-Maya/dp/0321383532/ref=pd_bxgy_b_img_a > > > > > > -- > > Matthew Thorson | VFX Student | Full Sail University | Computer > Animation > > > > > > > > > > -- > Shaun Friedberg > http://www.pyrokinesis.co.nz > "Fire Is Fun, When You Think About It" > > > > > > > -- > Matthew Thorson | VFX Student | Full Sail University | Computer > Animation > > > --~--~---------~--~----~------------~-------~--~----~ Yours, Maya-Python Club Team. -~----------~----~----~----~------~----~------~--~---