Autodesk Maya supports the use of Python-style scripting wherever you used to use MEL commands. The implementation of Python scripting in Maya provides the same access to native Maya commands as is provided through MEL. That is, all of the built-in Maya commands, such as sphere, ls, and so on, are accessible through Python.
Commands that are written as MEL scripts—which are actually MEL global procedures (procs)—are accessible using a call to access MEL (maya.mel.eval). For more information, see MEL/Python communication.
Python comes with a wide variety of standard modules that provide similar functionality. Refer to Python documentation for information on what is available and how to use these functions in your Python scripts.
When building PyQt for Autodesk Maya 2014, you must use the Microsoft 2010 Visual Studio compiler. This is different from the behavior in Maya 2012.
For instructions on how to build a copy of the PyQt modules, see the PyQt section under autodesk.com/maya-docs.
There is a Python command reference similar to the MEL command reference. For details on all Python commands, refer to the Python command reference documentation in Maya Help.
You can access the help by selecting Help > Python Command Reference or open the Maya Help (Help > Maya Help), and when the Help appears, click CommandsPython at the bottom of the navigation frame.
Maya installs Python with your Maya installation. Maya uses Python version 2.7.3 on all supported platforms. The standalone Python shell for Maya is named mayapy.exe on Windows and mayapy on Linux and Mac OS X.
For information about getting started with Python, including reference material and resources, see:
Maya runs any Python commands in the userSetup.py file whenever it starts up. You can use this file to set up your working environment or execute commonly used Python commands such as importing the maya.cmds module.
The userSetup.py script is executed during the initialization and setup phase of Maya; therefore, only commands which set up your working environment and have no dependencies on Maya functionality can be successfully run in this script.
You can use maya.utils.executeDeferred() to delay code execution until after the Maya scene is initialized. For more information, see maya.utils.
To add items to your path in Python, do one of the following:
Here is an example of appending sys.path
import sys sys.path.append( '/Users/jdoe/maya/Scripts' )
If you have a MEL script in your path, you do not need to source it before accessing any single global procedure it contains with the same name. However, Python requires you to import a script explicitly before accessing any classes or functions it contains; for example:
# This will access the function "bar" in the file "foo.py" import foo foo.bar()
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License