View Full Version : I don't get it...Python / MEL files system
11-28-2010, 05:56 PM
Just started with learning how to script with python / MEL.
I understand the syntax and the scripting (I allready have some solid scripting backgroudn).
But I don't understand the system in how to create / build scripts?
When I script in a .py file, how can I easily execute it in maya? The only way I found so far is by copy pasting it in the script editor of Maya, pressing execute.
Also I don't get when you work with several python files for classes and so on. How do you embed them with each other when only can copy paste it in the script editor?
But this is no way for scripters to build something easy to use for artist? It their not a way that they can run scripts by just dragging script or a more easy access?
I found out that you need to place your scripts in the script folder in mydocument of maya. But i do not see the advantage of doing this.
I'm used to a 3ds max environment. And I think I'm looking for a system similar to maxscript.
Is their anyone who can give me quick understanding?
Maybe I am missing something important.
thaanks a lot...Loving maya so far :)
11-28-2010, 06:07 PM
If you are developing a mel script, the best way is to code your script in a appropriate text editor, save it and do something like:
In python you can do the same thing. Instead of doing a source statement, you do an import.
or (not recommended)
from myscript import *
If you change your script then you can do a reload()
import myscript as ms
This way you can develop your scripts and execute them in maya. Your scripts have to be placed somewhere in the PYTHONPATH so that maya can find them.
12-13-2010, 10:34 AM
I use notepad++ to code Maya scripts. I think there are some built in functions that enable you to execute scripts as well.. but I actually don't know how really.. I'd suggest to do like haggi said: just put that stuff on a shelf button, save in Text Editor and press the shelf button again.
For top notch scripting (imho): you need a commandPort in Maya to make it source your script from outside.
But different from what haggi said for python I use the command execfile (http://docs.python.org/library/functions.html#execfile)to make it available in Maya. This way it does not depend on weather the file is in some pythonpath already.
But @haggi: Is that ok this way? I mean I do that for years now. Seems to work. But should I rather import it?
I actually set up a kind of hacked pipeline: I used Autohotkey to hook on Ctrl+Enter on Notepad++. If that is pressed I for script type py or mel, then look if there was a selection made. If yes: put selection to a file. If not: take current file. Then run py script that connects to the Maya commandPort and runs exefile(thatFile). works like a charm ;]
12-13-2010, 10:04 PM
Everything that works fine for your is okay ;)
I perfer the pythonic way of importing and reloading scripts. I never used the execfile() method. I have no idea how it behaves in a complex python project.
12-13-2010, 10:55 PM
me neither :D
Our maya part of the toolchain is entirely Mel-based. And I'm slowly implementing any news in python now..
Just had a look: I run the couple of py scripts via execfile as well. I mean I'd love to do it properly! Can I setup a PYTHONPATH when Maya loads our plugin, and runs the startup.mel? Or is it too late and the PYTHONPATH would have to be set up before?.. I bet I can do this in realtime, can I?
12-14-2010, 08:24 AM
Shoud be no problem to set the
variable anytime you need it, or add the path to
But normally you should do it before you start maya or maybe in the userSetup.py script.
12-14-2010, 08:24 AM
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.