Adverti horiz upsell
Using Eclipse as a Maya IDE
Using Eclipse as a Maya IDE
rbublitz, updated 2014-05-11 01:55:25 UTC 286,361 views  Rating:
(15 ratings)
Page 3 of 4

 

 

D. Maya Python Autocompletion

Eclipse Maya Autocompletion has files for Python commands as well as the Maya API.  Not only does this provide autocompletion but also displays any associated documentation (generated from the Maya docs).

a.  Once the Maya command library is imported, typing a period will bring up the various available commands.  Using the up and down keys will highlight the various options.  The associated documentation is displayed in a text box to the side.

autocomplete_PythonCommands

 

 

b. After importing a Maya API library, typing the library followed by a period will bring up the class options.  The documentation for the class is also displayed.

autocomplete_APIClass

 

 

c. After a class name has been assigned, 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.

autocomplete_APIFunctions

 

 

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

autocomplete_APIEnums

 

 

e. 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.

autocomplete_APIAllEnums

 

Setting it up

 

The Maya Python API .pyc files do not contain the proper documention information for autocompletion to function properly.  The autocompletion stub files exactly duplicate the classes and methods and attributes structure.  They are not functional, but instead include only the associated documentation which is culled from Maya’s own documentation.

This results in 2 sets of files– one with the actual functional files and one not functional but with the appropriate structure to allow autocompletion.  The stub files are in a single directory and have the extension .pypredef.  These are specified with Pydev using the "Predefined" tab.

 

1. In Pydev, go to "Window/Preferences/Pydev/Interpreter - Python"

2. Click on "Predefined" tab

3. Click on "New" and navigate to the directory containing the .pypredef files

4. Click on "Apply"

5. Refresh the project and/or restart Eclipse if the autocompletion is not working immediately. 

 

When trying access autocompletion, press Ctrl+Space in order to force the autocompletion options if they don't pop up after typing a dot.

 

Note: If you are also using Pymel autocompletion, be aware that that package also provides pypredef files for the Python API.  However, the structure is a bit different and does not provide any of the Maya class/method docs.

The "Predefined" tab is sorted alphabetically and there is a good chance that Pymel's API files could take precedence - basically clobbering the other API files.  I recommend removing the maya.OpenMaya, maya.OpenMayaAnim, etc. files from the Pymel autocompletion directory so that there are no duplicate files.

 

Regarding the import paths:  I did find there can be slightly different behaviour with the pypredef paths.

The .zip file has a maya/ directory with the OpenMaya*.py libraries inside - this matches the actual Maya library path structure.  This is what works for me on Windows.

However, if you are on Linux or if it's not working for you on a Windows machine, then you can rename the stub files to include "maya." in front of each library.  pypredef then recognizes this when you import maya.OpenMaya* in Eclipse.

 

Hints and Tips 

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.