Cancel
Showing results for 
Search instead for 
Did you mean: 

How to Debug Python in NX?

Genius
Genius

Is there a way to debug Python running in NX?  

 

SInce it is running from NX, I've not found a way to connect to the code like you would from Visual Studio C++. I'm using PyCharm but am glad to switch to something else if there is a way to step through my code.  

 

Mark

9 REPLIES

Re: How to Debug Python in NX?

Genius
Genius

I figured it out using Visual Studio 12.  For anyone else looking to do this, here is what I did. I'm guessing it is something similar with other IDEs or on other platforms.

 

1.) Get the Python Tools for Visual Studio https://pytools.codeplex.com/

 

2.) Get the pdbs for Python for mixed mode debugging.  I'm using NX10 which currently uses Python 3.3.2 64 bit. https://pytools.codeplex.com/wikipage?title=Symbols%20for%20Python%20mixed-mode%20debugging  (see below for how to get your version).

 

3.) Follow the instructions in the above link on setting up the symbols.

 

4.) Run NX.

 

5. In VS, click "Attach to Process" and select "Native code" and "Python code".  Then select the ugraf.exe process

 

5.) Run your python code in NX.VS should stop at any breakpoints you set.   

 

Note that if you get the wrong PDBs or don't set the path right in VS, I either got an error or a message in VS saying PDB not loaded.

 

If you are reading this in the future (I hope NX19 is really coolSmiley Happy!), you can get the exact Python version being used by NX by clicking the "Developer" tab, then Edit and pasting the following code, then checking the NX log (File/Help/Log File)

 

 

 

print (sys.version) #parentheses necessary in python 3.

 

Python(stdout): 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)]

 

 

Re: How to Debug Python in NX?

Siemens Phenom Siemens Phenom
Siemens Phenom

Mark,

 

Thanks for taking the time to share this!

 

Regards,

 

Steve

 

Re: How to Debug Python in NX?

Experimenter
Experimenter

Should this work for Visiual Studio Express? I can't get breakpoints to work.

 

When I insert a breakpoint, I get the warning:

The breakpoint will not currently be hit. No symbols have been loaded for this document.

Re: How to Debug Python in NX?

Siemens Phenom Siemens Phenom
Siemens Phenom

I don't think the debugging facility is supported in the VS Express editions. VS Express doesn't support debugging at all, for any program, in any language. Certainly this was the case a couple of years ago, and I suspect that it may still be true today.

山田
yamada

Re: How to Debug Python in NX?

Experimenter
Experimenter
It turns out, the I was having a problem because I was using an external python build (anaconda). After reverting back to the internal build, this works fine (even with visual studio 2017 express).

Re: How to Debug Python in NX?

Experimenter
Experimenter
you mentioned "5.) Run your python code in NX."
how to run python code?
the only one way to run python code I know is jounal play.

but I want to run python code in .menu or trb file which run dll file.

Re: How to Debug Python in NX?

Siemens Phenom Siemens Phenom
Siemens Phenom

If you've created myapp.py, then I'd guess that you can use "myapp" in the ACTIONS field of a custom menu item or a button. This sort of thing is described in the MenuScript User's Guide. It probably doesn't mention Python code, but I would expect Python code to be usable in more-or-less the same way as a DLL (for example). Caveat: I've never tried this, so I could be wrong.

山田
yamada

How to Run in .menu file with python code

Experimenter
Experimenter

thank you for your answer.

 

I use full path of python file(ex C://myapp.py) in the  ACTIONS field of a custom menu item or a button.

 

but it does not work. Does anybody knows how to run python file in .menu file?

 

 

Re: How to Run in .menu file with python code

Siemens Phenom Siemens Phenom
Siemens Phenom

I use the newer ribbon tab/group/etc. customization files rather than the old toolbar/menu files.

 

In a .rtb file, I simply specify the full path to the .py journal after the ACTION label in a BUTTON definition.