
mel import * # Delete any existing scene file ( newFile = None, force = None ) # Create the "Hello World" bevelled text. # helloworld4.py: The fourth and fanciest Hello World Python script for Maya from maya. The long version or the short version, so the following line has the Turned into an optional Python keyword argument. You can call any MEL function this way from Python and do the same So our Python script just invoked the following MEL command:ĬonfirmDialog -message "Hello World!" -button "OK" Eventually, you get the actual output from our Py "from maya import mel print mel.pySource" īut back to the example.

For example,Įven the MEL functions defined by the Python plugin itself did get wrapped: Wrappers for commands defined in third-party plugins.

The advantage of this dynamic module creation is that you even get The exact number of functions depends on the plugins you have loaded. Py "from maya import mel print len(dir(mel))" This can take aįew seconds as there are quite a lot of MEL commands in Maya. Maya is queried for all existing MELĬommands and appropriate Python wrappers are created. What actually happens during these few seconds is that the mel module Is imported (which might already have been the case when you already This progress window appears the first time the mel module Up and it takes a few seconds before the actual dialog from our script PySource) you might notice that there is a little progress window popping This script uses the mel module that contains Python wrappersĪround all MEL commands found in Maya. Package, otherwise you will get an ImportError exception) (in addition to the Python plugin this also requires the Maya Python confirmDialog ( message = "Hello World!", button =) # helloworld2.py: The second Hello World Python script for Maya from maya import mel mel. The Python package called maya comes into play. We could somehow communicate with Maya and do stuff with it. Thing to do, but for the ultimate experience it would be desirable if
#Maya python setattr translate code#
Being able to execute Python code is always a pleasing You that executing MEL code failed but more details about this will thenīe available in the Script Editor. See how this is done in a short moment) and this MEL code produces an error, If you are executing MEL code from within your Python script (you will Printed in the output window (or the console if you are not under Windows). The MEL command fails which you will notice in Maya's status line and in When any code executed by pySource or python raises an exception, We misspelled the print statement and executed the script. When there is an error in your Python script. The Python plugin defines oneĪdditional MEL command, python, which you can use to executeĪs you already noticed the output from the print statement isĭirected to the Output Window. It searches for a Python script at the same locations where MEL The pySource command is equivalent to the MEL command source.

Is working and you can execute Python code from within Maya. If you have a look at the Output Window (or the console) you should see To execute this line hit Ctrl+Enter or the Enter key on the numpad. (this assumes you have successfully installed (and loaded) the Maya Python Now launch Maya, open the MEL Script Editor and enter: This is the same location where you would put MEL scripts. Stick it into your Maya directory under maya//scripts. So write a file helloworld1.py with the above contents and # helloworld1.py: The very first Hello World Python script for Maya print "Hello World!"īut at least you can use this script to test your Python plugin.
