## Using Wing with Autodesk Maya

Wing Pro is a Python IDE that can be used to develop, test, and debug Python code written for Autodesk Maya, a commercial 3D modeling application.

This document describes how to configure Wing for Maya. To get started using Wing as your Python IDE, please refer to the tutorial in Wing's Help menu or read the Quickstart Guide.

### Debugging Setup

When debugging Python code running under Maya, the debug process is initiated from outside of Wing, and must connect to the IDE. This is done with wingdbstub according to the detailed instructions in the Debugging Externally Launched Code section of the manual. In summary, you will need to:

• Copy wingdbstub.py from your Wing installation into a directory that will be on the sys.path when Python code is run by Maya. You may need to inspect that (after import sys) first from Maya, or you can add to the path with sys.path.append() before importing wingdbstub.
• Because of how Maya sets up the Python interpreter, be sure to set kEmbedded=1 in your copy of wingdbstub.py
• In your code, where you initiate debugging, use the debugger API to ensure the debugger is connected to the IDE before any other code executes, as follows:
import wingdbstub
wingdbstub.Ensure()

• In some cases you may need to edit wingdbstub.py to set WINGHOME to point to the directory where Wing is installed. This is usually set up automatically by Wing's installer, but won't be if you are using the .zip installation of Wing. Note that if you edit wingdbstub.py after Maya has already imported it then you will need to restart Maya to get it to import the modified wingdbstub.
• Then click on the bug icon in lower left of Wing's window and make sure that Accept Debug Connections is checked.

At this point, you should be able to reach breakpoints by causing the scripts to be invoked from Maya. In Maya 2018 at least, running a script does not set up the file name in the compiled Python code correctly, so breakpoints only work in modules that are imported into your top-level script. Breakpoints in the main script may work in older Maya versions.

Once debugging starts, when a breakpoint or exception is reached, Wing should come to the front and show the place where the debugger stopped. Although the code is running inside Maya, editing and debugging happens inside Wing.

#### Avoiding Crashing in Maya 2020

Maya 2020 may use an old copy of OpenSSL that leads to crashing on 10th (Ice Lake), 11th (Rocket Lake) or 12th (Alder Lake) generation Intel CPUs. The problem occurs when import wingdbstub is reached, crashing Maya completely.

There are two ways to work around this problem:

1) Uncheck the Debugger > Network > Use Digests to Identify Files preference in Wing. This turns off a part of Wing's debugger implementation that calls hashlib, and thus avoids the crash.

-or-

2) Set Windows system environment variable OPENSSL_ia32cap to the value ~0x20000000 before starting Maya.

### Using Maya's Python in Wing

You can use the mayapy executable found in the Maya application directory to run Wing's Python Shell tool and to debug standalone Python scripts.

To do this, select Command Line for Python Executable in Project Properties, accessed from the Project menu, and then enter the full path of the mayapy file (mayapy.exe on Windows).

### Better Static Auto-completion

Setting Python Executable in Wing's Project Properties, as described above, is also needed to obtain auto-completion for Maya's Python API.

At least in some versions of Maya, Wing cannot statically analyze the files in the Python API without some additional configuration. As a result, it will fail to offer auto-completion for the API. The solution to this depends on the version of Maya.

#### Maya 2020

In Maya 2020 it is necessary to download and install the Maya 2020 devkit from the devkit downloads listed on the Autodesk website. The pi interface files will be located in devkitBase\devkit\other\pymel\extras\completion\pi inside your Maya 2020 installation directory. This can be added to the Source Analysis > Advanced > Interface File Path preference in Wing.

#### Maya 2018

Maya 2018 ships with .pi files in the devkit/pymel/extras/completion/pi subdirectory of the Maya 2018 install directory. This can be added to the Source Analysis > Advanced > Interface File Path preference in Wing.

#### Maya 2016

Maya 2016 is missing necessary developer files so you will need to download and install the Maya 2016 devkit which should create devkit\other\pymel\extras\completion\py\maya\api in your Maya installation. This can then be used by making the following edits:

• In "OpenMaya.py" add from _OpenMaya_py2 import *
• In "OpenMayaAnim.py" add from _OpenMayaAnim_py2 import *
• In "OpenMayaRender.py" add from _OpenMayaRender_py2 import *
• In "OpenMayaUI.py" add from _OpenMayaUI_py2 import *

This method is based on this forum post.

Instead of editing files in the Maya installation, it is also be possible to add .pi files with the added source. For example, placing OpenMaya.pi with contents from _OpenMaya_py2 import * in the same directory as OpenMaya.py causes Wing to merge the analysis of the *.pi file with what is found in the *.py file.

Alternatively, place these files in another directory that is added to the Source Analysis > Advanced > Interface File Path preference in Wing.

You will also want to set the Python Executable in Wing's Project Properties to Command Line and then enter the full path to mayapy.exe so that the API is on the Python Path and you are using the correct version of Python.

#### Maya 2011+

Maya 2011+ before 2016 also shipped with .pi files that can be used as described for Maya 2018 above.

#### Older Versions

For older Maya versions, .pi files from the PyMEL distribution at http://code.google.com/p/pymel/ may be used. Just unpack the distribution and add extras/completion/pi to the Source Analysis > Advanced > Interface File Path preference in Wing.