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.
- Search for the devkit for your Maya version towards the bottom of Autodesk’s Maya Development Center page.
- Download and extract it.
- 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
- e.g. C:\Program Files\Autodesk\Maya2019\devkit
- 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.
- Click on File->Settings
- Under the Project group, click on the Python Interpreter tab
- Click the gear icon on the far right and then the “Add…” option.
- In the Add Python Interpreter window, click the System Interpreter tab
- Click the “…” button to browse for a new one.
- Browse and select your mayapy executable (e.g. C:\Program Files\Autodesk\Maya2019\bin\mayapy.exe)
- Confirm the mayapy interpreter is selected now and click OK.
- PyCharm will have given the interpreter some default name. Let’s give it a more useful name.
- Click the gear icon on the far right and then the “Show All…” option.
- Select the mayapy interpreter that you just added and click the edit icon to edit.
- Rename the interpreter and click OK
Add the devkit Python stubs to PyCharm#
Continuing from the previous section, you should still be on the Python Interpreters window.
- Click the show paths icon
- Add the path to the Python stubs that we prepared earlier
- e.g. C:\Program Files\Autodesk\Maya2019\devkit\other\pymel\extras\completion\py
- Remove the Maya’s site-packages path to avoid conflicts with the stub files
- C:\Program Files\Autodesk\Maya2019\Python\Lib\site-packages
- 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.
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:
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.
- Click on File->Settings.
- Under the Tools group, click on the External Documentation tab
- Add a new entry by clicking the “+” button.
- Set Module Name to: maya.cmds
- Set URL/Path Pattern to: http://help.autodesk.com/cloudhelp/2019/ENU/Maya-Tech-Docs/CommandsPython/{element.name}.html
- 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.