How to execute NXOpen Python code from any command prompt?
SolutionThere are at least two ways for executing a Python source code (.py) file with NXOpen APIs without a NX GUI (graphical user interface).
Example for second option (assuming NX 2306 and an external Python 3.10 distribution in D:\Python310):
.
Command Prompt output:
>set PATH=%UGII_BASE_DIR%\NXBIN;d:\python310;%PATH%
>set PYTHONPATH=D:\Python310;D:\Python310\DLLs;D:\Python310\Lib;D:\Python310\Lib\site-packages;%UGII_BASE_DIR%\NXBIN\python
>python report_nx_version.py
NX Full Version string is v2306.0.0.4000
UGII_PYTHONPATH is only required and used by NX internal/external because the common PYTHONPATH was blocked by the JACK toolkit which used another Python version in earlier days.
So if you don’t need Python debugging with Eclipse or similar, then this approach makes it easier and faster as you don’t even need a NX command prompt.
See also:
NX Open Programmer's Guide - Use external Python distribution
https://docs.sw.siemens.com/en-US/doc/209349590/PL20221117716122093.nxopen_prog_guide/xid1124926
NX Open Programmer's Guide - Executing Batch Applications - NX Open for Python
https://docs.sw.siemens.com/en-US/doc/209349590/PL20221117716122093.nxopen_prog_guide/xid862706