PTVS with Mayapy and Pymel

Oct 21, 2011 at 5:40 PM
Edited Oct 21, 2011 at 5:43 PM

 

I spent a few hours getting this to work, so I wanted to share my experience on how I got it working for other's benefit.  And if the PTVS devs want to chime in on how this can be improved, that would be great also.

This is how I got PTVS working with Mayapy and Pymel.  This is assuming Maya 2012 64-bit:

- Install Visual Studio 2010, Maya 2012 64-bit, PTVS

Make a new Interpreter:

- In Visual Studio, Tools->Options->Python Tools->Interpreter Options.  Click Add Interpreter.

- Name:  Mayapy 2012 64-bit

- Path: C:\Program Files\Autodesk\Maya2012\bin\mayapy.exe

- Windows Path:  <leave blank>

- Architecture: x64

- Language Version: 2.6

- Path Environment Variable: PYTHONPATH

Create a new Python Project:

- File->New->Project.   Other Launguages->Python->Python Application.  Fill out name, hit Ok

- Right-click Search Path->Add Search Path.  Set it to C:\Program Files\Autodesk\Maya2012\Python\lib\site-packages\pymel\core

- Change the .py file to test something in pymel:
   import pymel as pm
   print(pm.mel.getenv("PYTHONPATH"))

- Hit F5 to test

 

With this setup, I was able to debug and get Intellisense for Pymel and everything seems to be working good.

The only issue that comes up is that when Debugging, there are 3 exceptions that get triggered on startup.  This is happening within the Pymel code.  If I hit 'Continue' each time however, execution proceeds normally.  Is there a way to ignore these exceptions?

 

Coordinator
Oct 21, 2011 at 6:41 PM

Thanks fasteddo for investigating & writing this up!  i'm sure others will benefit as well.

Re exceptions, see the Exceptions dialog where you can fine tune the filter:

see 2nd comment in this thread: http://pytools.codeplex.com/discussions/271752

 

 

Dec 18, 2013 at 4:03 AM
in PTVS 2.0 "Add Interpreter has been changed to Add Environment"
https://pytools.codeplex.com/discussions/456300
I followed the instructions there to add the mayapy.exe as an Environment
Image
after creating a python app project and adding the "MayaPy" environment I tried testing it in the MayaPy Interactive window
>>> import maya.cmds as cmds
>>> print(cmds.internalVar(userAppDir=True))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'internalVar'
>>> 
strangely the intellisense seems to pick it up and know what modules are available in maya.cmds
Coordinator
Dec 18, 2013 at 5:41 AM
I don't have it handy to check, but it is possible that internalVar doesn't always exist. For example, with this code:
if False:
    internalVar = 123
We will show internalVar as a possible completion, even though it's never going to be available. We don't filter it out because we can't evaluate all if conditions reliably, so we have to assume that it may run at some point. This is especially important if it's a condition that is set or changed by other code - we just don't have the sequence analysis necessary to handle it correctly.

Try and have to look at the source code to see where the name is set and whether it is in a conditional block. You may just have picked an unlucky name to test with.