Using Python Scripting in Maya

Python scripting can be used within Maya in order to create effects, models and imaging. It is one of the many scripting languages that can be used with Maya. Maya has a Python plug in if you prefer to use this type of script for editing and compositing. Python can be used in the exact same spot where the MEL script is used.

What Is Python?

Python is a type of programming language that can be used on all different operating systems. This allows these systems to be fully integrated by using 1 script. This script is free, as it has an open source license. Python is popular because it is powerful and fast. It contains dynamic data types, extensions for other modules, the ability to embed applications and can easily integrate with CORBA, NET and COM. This is easy to learn and user friendly.

Getting It to Work

Python script will not automatically run in Maya. A plug-in is needed, and the Python interpreter will need to be functioning. This Python is called Hello World. If everything has been properly installed, then within the MEL scripting window, Hello World will be printed. Now that everything is working, the Python code can be used within the system. One other main difference is that MEL script uses flags and Python does not.

Benefits

Python is popular because it uses clear syntax and will use line returns and tabs as code structure. This creates easy to read, clear programs. This versatile and easy syntax makes it possible to rapidly develop programs. It is very easy to learn and used by non computer science experts that do not have extensive scripting experience. Artists, Scientists and statisticians have a lot of success using Python. MEL scripting can take awhile, as there are some UI layouts and syntax issues that can take a long time to figure out. Autodesk has also completely documented how to go from EML to Python. The documentation is excellent and a great resource for those trying to learn Python.

Interpreter

The system will need to have the Python interpreter in order to use the script. In the latest versions of Maya, this interpreter is built into the program.  Programs can be composed completely in Python script, and the system will then interpret this in Maya. Think of Python like a wrapper around the MEL scripting language. Programs can be developed in Eclipse, WordPad, TextMate, Xcode or TextEdit, and then pasted into the Maya Script editor in order to be executed.

Commands

All Python programs need to be started with the same command; import maya.cmds as cmds. This tells the Maya Script editor to import all of the Python commands and use them within Maya.  All of the necessary codes can be looked up in the Python command reference site. Try out some various scripts. It is also possible to import code directly into the Maya script editor.  It is best when importing the script to have it saved on a file on the system, as downloading script directly from the Internet can cause problems. A file path will be created to the saved script.