Mati Codes
# _  _ ____ ___ _    ____ ____ ___  ____ ____ #
# |\/| |__|  |  |    |    |  | |  \ |___ [__  #
# |  | |  |  |  |    |___ |__| |__/ |___ ___] #
#                                             #
# _  _ ____ ___ _    ____ ____ ___  ____ ____ #
# |\/| |__|  |  |    |    |  | |  \ |___ [__  #
# |  | |  |  |  |    |___ |__| |__/ |___ ___] #
#                                             #

Feb. 8, 2021

HOW TO SETUP PYCHARM FOR MAYA SCRIPTING WITH AUTOCOMPLETE AND EXTERNAL DOCUMENTATION


Let's take a look at how to set up autocomplete and external documentation in PyCharm for maya.cmds and the Maya API (OpenMaya) to help speed up your development.

Prepare the devkit

For autocomplete, you'll need to download the Autodesk Maya devkit to get the python stubs.

  1. Search for the devkit for your Maya version towards the bottom of Autodesk's Maya Development Center page.
  2. Download and extract it.
  3. For autocomplete, you'll just need a folder from the devkit called "other". Copy the folder named "other" from within and paste it into the devkit folder of your Maya installation
    1. e.g. C:\Program Files\Autodesk\Maya2019\devkit
    2. You can keep the complete devkit installed somewhere else and reference it from there if you prefer. Just note the path for later.

Setup the mayapy interpreter within PyCharm

You'll want to setup mayapy as a system interpreter within Maya. As a system interpreter, you can easily use it across PyCharm projects.

  1. Click on File->Settings
  2. Under the Project group, click on the Python Interpreter tab
  3. Click the gear icon gear icon on the far right and then the "Add..." option.
  4. In the Add Python Interpreter window, click the System Interpreter tab
  5. Click the "..." button to browse for a new one.
  6. Browse and select your mayapy executable (e.g. C:\Program Files\Autodesk\Maya2019\bin\mayapy.exe)
  7. Confirm the mayapy interpreter is selected now and click OK. interpreter path
  8. PyCharm will have given the interpreter some default name. Let's give it a more useful name. interpreter path
    1. Click the gear icon gear icon on the far right and then the "Show All..." option.
    2. Select the mayapy interpreter that you just added and click the edit icon edit icon to edit.
    3. Rename the interpreter and click OK
      rename interpreter window

Add the devkit Python stubs to PyCharm

Continuing from the previous section, you should still be on the Python Interpreters window.

  1. Click the show paths icon show paths icon
  2. Add the path to the Python stubs that we prepared earlier
    1. e.g. C:\Program Files\Autodesk\Maya2019\devkit\other\pymel\extras\completion\py
  3. Remove the Maya's site-packages path to avoid conflicts with the stub files
    1. C:\Program Files\Autodesk\Maya2019\Python\Lib\site-packages
  4. Click OK and confirm and close out of all settings windows.

Now you're ready to test it out. Import maya.cmds and start typing a command.
pycharm autocomplete
If you take a look at the OpenMaya API, you'll see that you get inline documentation too. Put your cursor on a class or function and press Ctrl+Q:
pycharm inline doc
The maya.cmds stubs don't have documentation included, but we can set up external documentation for a quick reference.

Setup external documentation

Make sure you're using PyCharm 2018.3 or newer. These macros aren't working in older versions.

  1. Click on File->Settings.
  2. Under the Tools group, click on the External Documentation tab
  3. Add a new entry by clicking the "+" button.
  4. Set Module Name to: maya.cmds
  5. Set URL/Path Pattern to: http://help.autodesk.com/cloudhelp/2019/ENU/Maya-Tech-Docs/CommandsPython/{element.name}.html url pattern
  6. Click OK and close out of the settings.

Now, when you put your cursor on a Maya command press Shift+F1 or click on View->External Documentation. It will open up a new tab in your browser with the documentation for that specific command.

>>>

Tags

openmaya, python, scripting, maya, IDE, autocomplete, pycharm, documentation