Before writing your plug-in, set up your environment.
Two different Python APIs, Maya Python API 1.0 and Maya Python API 2.0, are included with Maya. Maya Python API 1.0 is generated from the Maya C++ API. It is more comprehensive than Maya Python API 2.0, but less Pythonic than API 2.0. Maya Python API 2.0 is more Pythonic than Maya Python API 1.0. Its structure will be more familiar to Python programmers, and will be more intuitive to use as a result.
Two versions of a simple Hello World plugin are provided:
Open an editor and cut-and-paste the source code into a new file. In keeping with Maya's Python naming conventions, Python API 1.0 files should have the "py1" prefix, and Python API 2.0 files should have the "py2" prefix. For example, the API 1.0 version can be named "py1HelloWorld.py" and the API 2.0 version can be named "py2HelloWorld.py".
Save your file to MAYA_PLUGIN_PATH. Plug-ins placed in that directory are automatically picked up by Maya if your environment has been set up according to the instructions in Setting up your build environment.
Open the the Plug-in Manager. Click on Window > Settings/Preferences > Plug-in Manager. You can load your plug-in from the plug-in manager.
You can also load the plug-in from the Script Editor using maya.cmds.loadPlugin(). For example:
import maya.cmds maya.cmds.loadPlugin("py2HelloWorld.py")
Once your plug-in is loaded, the command defined by the plug-in will be added to the maya.cmds module. You can now call the command from the Script Editor.
import maya.cmds as cmds cmds.py2HelloWorld()
The command will be echoed and "Hello World!" will be printed below it.
import maya.cmds as cmds cmds.py2HelloWorld() Hello World!