Using Eclipse as a Maya IDE

I've recently discovered the Eclipse editor. I'm not sure how long it's been around and why I didn't know about it before but I am very impressed with it. I've been using jEdit since 2001 and it has served me well during that time writing mel, C++ plugins and python for Maya. jEdit became my Maya IDE. But I think Eclipse outshines jEdit.

This tutorial will outline the steps I've taken to make Eclipse my Maya IDE. The Maya Editor plugin enables communication directly with Maya. It also accesses various sets of documentation. Python programming for Maya has been enhanced by adding autocompletion for the Maya API and Pymel. If there are more features you think should be added, please contact me and I'll see what I can do.


A. Basic resources.


B. Maya Editor


This is a plugin for Eclipse that turns it into a Maya IDE. As it is Python-centric, it also requires the Pydev plugin.

Features include:

  • Send the entire contents of an editor to Maya
  • Send a highlighted selection to Maya
  • Get results back from Maya in it's own console view
  • Anything done within Maya's own script editor is also echoed in the console view
  • Change the port number of the socket at any time
  • Open up documentation for Maya's Python API, Python Commands, Pymel and WPF

Setup:

1 .Place the downloaded .jar file in the eclipse/plugins/ directory and relaunch Eclipse.

2. In Maya, create a new shelf button with the following code or put it in the Startup script

import maya.cmds as cmds

if cmds.commandPort(':7720', q=True) !=1:

cmds.commandPort(n=':7720', eo = False, nr = True)


Command hotkeys:

  • Ctrl+Return -> Send editor contents to Maya
  • Ctrl+' -> Send highlighted selection to Maya
  • Ctrl+] -> Reconnect Eclipse to Maya

Preferences:

  1. Port Number - By default, the port number has been set to 7720. It can be changed at any time. Remember to press the "Reconnect Eclipse to Maya" button. This is handy if you have more than one instance of Maya open at once.
  2. Update Interval: This sets how often Eclipse checks to see if there's any new text in Maya. It is in time units of seconds.
  3. The last four text fields set the location of the various sets of documentation. They can be entered either as web URLs or local file paths depending on where the docs are located. For example, the Maya docs are available on Autodesk's website. However, Pymel docs would be local to your machine.

C. Pymel Autocompletion

Eclipse provides autocompletion for Python classes and functions. Of course I want to take advantage of this for any APIs I want to use with Maya. The first one I set up was for pymel (ver. 0.7.9).


Steps to get autocompletion to work for pymel in Eclipse (using pydev plugin).
1. Open "Window/Preferences"


2. Click on left flyout menu "Pydev/Interpreter-Python"

3. In "Python interpreters" window, set path to the python interpreter that is compatible with the version of Maya.

4. In "System PYTHONPATH" window set path to the PARENT directory of BOTH pymel and the maya python API (ie. ..../Maya_2008/Python/lib/site-packages)

5. In the "Forced builtin libs" add listings to the various modules of BOTH packages:
pymel.core
pymel.ctx

pymel.node
pymel.path
pymel.scene
pymel.vector
maya.OpenMaya
maya.mel
maya.cmds

6. Click "Apply". pydev then parses the specified modules for the interpreter.

D. Maya Python API Autocompletion


a. Typing the first few letters of a class and pressing Ctrl + period ( in the example below an M was typed) brings up the available class options that will complete the class name. Using the up and down keys will highlight the various options. The associated documentation is displayed in a text box to the side.

b. After a class name has been typed, enter a period and the associated functions, attributes and enum options are displayed. The example below shows a typical function with documentation displaying the needed arguments.

c. The Maya C++ API enums are made available as part of the class.

d. Since Python does not have the equivalent of an enum, non-functional classes have been included that collect the associated enum values for enum type so that all possible options are displayed in one place.

e. Setting it up.

The actual Maya Python API .pyc files do not contain the proper information for autocompletion to function properly. These new autocompletion files (see link at top of this page) duplicate the directory structure and file names and include the classes and functions that belong with each one. They are not functional, but instead include only the associated documentation which is culled from Maya's own documentation.

This ends up with 2 duplicate API directory structures; one with the actual functional files and one not functional, but with the appropriate structure to allow autocompletion. One set will be used by the Python interpreter and one set will be used by the Python editor. In Eclipse, both the Python interpreter and editor share the same initial preferences, so it would initially seem that the duplicate API structures would clobber each other. But Eclipse offers a way to set additional source locations per project so that the editor is able to include a different file path from the interpreter.

Specify the appropriate python paths in Window/Preferences/Pydev. There you can specify the path to the Maya Python API directory and the directory to the duplicate non-functional API. Make sure the actual Maya API directory comes after the duplicate directory so that it takes precedence and will be the one used by the interpreter.

In the "Forced Built-ins" window, specify each API module so that the Python introspection is done for each. Remember to specify them by the module path (ie. maya.OpenMaya, maya.OpenMayaAnim, maya.OpenMayaCloth, maya.OpenMayaFX, maya.OpenMayaMPx, maya.OpenMayaRender, maya.OpenMayaUI). Click "Apply" and "OK".

f. Project Preferences

Each project has its own set of preferences. Highlight the project name in the Pydev Package window and go to File/Properties. This will bring up the window shown below. There you can specify additional source folders, either within a project or external to the project. In this case, specify the external directory path to the duplicate API directory (the one we want to access for autocompletion). Now within that project, any python files that are edited will have the autocompletion available.

To test it out:

  1. Edit a .py file
  2. Type from maya.OpenMaya import *
  3. Type M and press Ctrl+ period
  4. The autocompletion options should pop up.
  5. D. Hints and Tips

    1. The autocompletion feature of Eclipse brings up a list of completion options and a documentation window for any info that exists for the selected option. By default, the yellow doc window is displayed as a small square and for some options, the text doesn't fit and really isn't that readable. But if you click inside the yellow window, it gets focus and a scrollbar appears. This can be used to display all the available docs. Also, dragging the bottom of the doc window will increase the viewing area; this new size is then remembered each time the window is displayed.

    .