Cancel
Showing results for 
Search instead for 
Did you mean: 

Running batch NXOpen application

Hello,

 

I want to run separate python interpreter (Python 3.4.4) and do import NXOpen.  I use Windows 7 and NX 11

 

I set some env vars for that:

 

@ECHO off

set PY_INTERPRETER=C:\Python344

set UGII_BASE_DIR=C:\Siemens\NX11
set UGII_ROOT_DIR=%UGII_BASE_DIR%\UGII
set NX_BIN_DIR=%UGII_BASE_DIR%\NXBIN
set NX_PYTHON_DIR=%UGII_BASE_DIR%\NXBIN\python
set NX_VER=v11

set UGII_ENV_FILE=%UGII_ROOT_DIR%\ugii_env.dat

set LD_LIBRARY_PATH=%UGII_ROOT_DIR%;%NX_BIN_DIR%;%NX_PYTHON_DIR%

set PYTHONPATH=%PYTHONPATH%;%LD_LIBRARY_PATH%;%PY_INTERPRETER%

echo %PYTHONPATH%

%PY_INTERPRETER%\python.exe

But I have an error:

 

Traceback (most recent call last):
  File "robust_parametrisation.py", line 13, in <module>
    import NXOpen
  File "C:\Siemens\NX11\NXBIN\python\sitecustomize.py", line 60, in load_module
    module = loader.load_module(None)
  File "C:\Siemens\NX11\NXBIN\python\sitecustomize.py", line 13, in load_module
    return super(NXOpenLoader, self).load_module(fullname)
ImportError: DLL load failed: The specified module could not be found.

On Linux it works well.

 

Could you help me?

 

Regards,

Anton

5 REPLIES 5

Re: Running batch NXOpen application

I did it.

Just added PYTHONPATH into PATH. And installed cython

Re: Running batch NXOpen application

Pioneer
Pioneer

Can you provide more information? I believe I have added pythonpath into my PATH and installed cython. Are you able to run NXOpen applications outside of NX using another environment? 

Re: Running batch NXOpen application

I'm not sure if I understood you correct, but NX have to be installed and you have to have a license for it. The you can use NXOpen.

If you wanna use it remotely, you shoul implement it yourself, like via RPC, client-server architecture, ...

Re: Running batch NXOpen application

Creator
Creator
Hi, for an academic project first time I am trying to use NX 12 with python using eclipse and i am having the same problem. Did you solve it already? If you have the solution can you please share?

Re: Running batch NXOpen application

Pioneer
Pioneer

Actually, I did. It takes a couple steps, but I'll try to outline what I did.

 

I use a batch file to launch NX, specifically the batch file for NXCustom.

 

I created a couple environment variables to help make this easier, the most important was %NX_PYTHON_ENV_PATH% which pointed to the root directory of a conda environment I had set up with my libraries and such. It's very important to note that NX seems to only work with the exact version of python specific to that version of NX - for NX12, that appears to be 3.6.1. I'll put a full dump of the packages in my python env at the bottom of this post. 

 

I added these lines to the batch file:

set NX_BIN_DIR=%NX_DIR%\NXBIN
set NX_PYTHON_DIR=%NX_DIR%\NXBIN\python
set NX_VER=v12

Now I begin the portion of the batch file that sets all the relevent NX environment variables. The echos are for my convenience and are not required. 

 

call activate nx12_venv
echo setting conda env path

set NX_PYTHON_ENV_PATH=%NX_DIR%\python_env
echo NX_PYTHON_ENV_PATH is %NX_PYTHON_ENV_PATH%
set PYTHONHOME=%NX_PYTHON_ENV_PATH%
set PYTHON=%PYTHONHOME%\python.exe
set UGII_PYTHON_HOME=%NX_PYTHON_ENV_PATH%
set UGII_PYTHONPATH=%NX_PYTHON_ENV_PATH%;%NX_PYTHON_ENV_PATH%\DLLs;%NX_PYTHON_ENV_PATH%\Lib;%NX_PYTHON_ENV_PATH%\Lib\site-packages;%UGII_BASE_DIR%\nxbin\python
set PYTHONPATH=%UGII_PYTHONPATH%
set UGII_PYTHON_LIBRARY_DIR=%NX_PYTHON_ENV_PATH%
set UGII_PYTHON_DLL=python36.dll

So presuming all that works, and you are now running NX with a UGII_PYTHON set to your custom environment.

 

You'll now want to set up eclipse so that the eclipse debugger can connect to NX and interrupt the process. I made a guide for this a couple months ago; I've attached a PDF of theguide explaining how this can be done.

 

Once you've followed the instructions to setup eclipse, any time you want to invoke the debugger add this to your python code:

            from test.test_importlib.namespace_pkgs.both_portions.foo.one import attr
            import sys;sys.path.append(r'C:\Users\!!!ENTER_YOUR_USER_DIR_HERE!!!\.p2\pool\plugins\org.python.pydev.core_6.4.4.201807281807\pysrc')
            import pydevd;pydevd.settrace()

 

 

Conda env packages (certanly not all required for NX to run, but worth noting if you end up needing any of them)

anaconda                  custom           py36h363777c_0
blas                      1.0                         mkl
ca-certificates           2018.11.29           ha4d7672_0    conda-forge
certifi                   2018.11.29            py36_1000    conda-forge
cycler                    0.10.0           py36h009560c_0
et_xmlfile                1.0.1            py36h3d2d736_0
freetype                  2.9.1                ha9979f8_1
glob2                     0.6                      py36_0
icc_rt                    2017.0.4             h97af966_0
icu                       58.2                 ha66f8fd_1
intel-openmp              2019.0                      118
jdcal                     1.4                      py36_0
jpeg                      9b                   hb83a4c4_2
kiwisolver                1.0.1            py36h6538335_0
libiconv                  1.15              hfa6e2cd_1004    conda-forge
libpng                    1.6.34               h79bbb47_0
libxml2                   2.9.8             h9ce36c8_1005    conda-forge
libxslt                   1.1.32            heafd4d3_1002    conda-forge
matplotlib                2.2.3            py36h31860fd_0    conda-forge
mkl                       2018.0.3                      1
mkl_fft                   1.0.6            py36hdbbee80_0
mkl_random                1.0.1            py36h77b88f5_1
numpy                     1.15.2           py36ha559c80_0
numpy-base                1.15.2           py36h8128ebf_0
openpyxl                  2.5.8                    py36_0
openssl                   1.0.2p            hfa6e2cd_1002    conda-forge
pandas                    0.23.4           py36h830ac7b_0
pip                       10.0.1                   py36_0
pyparsing                 2.2.0                    py36_1
pyqt                      5.6.0                    py36_2
pyside2                   5.6.0a1         py36h20f30f1_1004    conda-forge
python                    3.6.1                         2
python-dateutil           2.7.3                    py36_0
pytz                      2018.5                   py36_0
qt                        5.6.2                    vc14_1    conda-forge
scipy                     1.1.0            py36h4f6bf74_1
setuptools                40.2.0                   py36_0
sip                       4.19.8           py36h6538335_0
six                       1.11.0                   py36_1
sqlite                    3.25.2               hfa6e2cd_0
tornado                   5.1              py36hfa6e2cd_0
vc                        14                   h0510ff6_3
vs2015_runtime            14.15.26706          h3a45250_0
wheel                     0.31.1                   py36_0
wincertstore              0.2              py36h7fe50ca_0
xlrd                      1.1.0                    py36_1
zlib                      1.2.11               h8395fce_2