I am trying to 'connect' to NX Open API via MS Visual Basi Express 2012. I am using NX 9.0. In VS I am starting a new project using Templates: Visual Basic -> Windows Forms Application. Then in Form1.vb I put following code:
Imports NXOpen Imports NXOpenUI Imports NXOpen.UF Imports System Imports System.Windows.Forms Imports System.Drawing Imports System.Xml Imports System.Data Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Dim NxSession As Session = Session.GetSession Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
Project references indicate on:
During debugging of this code when reached
Dim NxSession As Session = Session.GetSession
I receive following error message:
I did another test and recorded a Journal in NX to build a standard block. I used recorded code in my application and received same error message during try to use GetSession method.
May I ask someone to help me what wrong is with my code / settings of the project? Are there some other libraries / dependencies missing? Where should I add them in VS project?
I've just did another test. Started NX command prompt, then changed directory to VS project\bin\Debug, then tried to launch exe file created during previous debug of my project application. This time received such error:
The libpart.dll not found is caused by the PATH variable. You need to put the root directory at the beginning of the path.
will put the root dir at the front of the existing path, and leave everything else alone.
The incorrect format error probably means that you built your executable as either a Win32 or an AnyCPU app. For NX9, you will have to build it as x64.
From your description, and from the error message, it sounds like you're just launching your program from within Visual Studio. That won't work, you have to run it from within NX. Go to File-->Execute-->NX Open (Ctrl+U), and navigate to your DLL or EXE file.
Also, for a simple "getting started" program like this, there's not much point in making it a Windows Forms app. A Console Application is simpler, and will be easier to debug/analyze if things continue to go wrong.
And, as Steve said, the "incorrect format" error probably means you're using the wrong target architecture.
Is there a reason you are not using the Siemens NX project templates/wizards?
If you install Vis Studio before NX, I think they are loaded automatically.
If you install Vis Studio after NX, you can set them up:
Search UGanswer (https://solutions.industrysoftware.automation.siem
Although just doing that search I find an article:
"Getting Started : The NXOpen Wizards do not work with VS Express"
with references to ZIp files with "generic" solutions set up properly for NX & VS Express.
Hope this helps...
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled
I got the same libpart.dll problem. So I added "%UGII_ROOT_DIR%;%PATH%" at the beginning of the "Path" environment variable, but it still gave me that error. Do you have any other ideas about this?
If you are trying to run your NXOpen .DLL from within the Visual Studio, then the Studio session needs to have inherited that setting, and you will have to attach to the running NX session.
We always suggest that you launch your Visual Studio session for NXOpen work from an NX Command Prompt, rather than from the start menu, an icon or a regular command shell. This should ensure that your Studio session inherits the necessary environment variables.
Please visit our support site:
Enter this in the first search field:
nxopen "getting started"
Then click on "nx_api", on the left side, under Document Type.
Open the article called "Getting Started: Index". It will show you a nice list a lot of common issues that users run into when they are starting to use NXOpen.
Thanks for the link. That is very helpful. I have read the page: Getting Started : The NX Command Prompt.
I have created a .bat file as told with the following contents:
(I am using VB, so I replaced VC with VB)
set UGII_BASE_DIR=<D:\NX 10.0>
set MSVCDir=<C:\Program Files (x86)\Microsoft Visual Studio 11.0\VB>
call "%UGII_BASE_DIR%\UGII\ugiicmd.bat" "%UGII_BASE_DIR%" AUTO
I have also added an environment variable called MSVCDir with the directory above.
However, when I double clicked on the batch file, the command window showed up and disappeared right away. Do you have an ideas about this?
Change it back to VC.
Instead of double-clicking the .bat file, open an NX Command prompt and type in the name of the .bat file and hit return. If it is throwing some kind of error, you should at least be able to see what it says.
I did so, but it tells me the syntax of the command is incorrect.
Besides, when I opened the command prompt from NX, it says "The specified ocnfiguration type is missing". This didn't show before.
Do you have any ideas?
Well, those angle brackets in your environment variable definition look odd. I think those are causing the syntax error.
Here is what my startup bat file looks like for MSVS 2012:
title %UGII_BASE_DIR% -- Visual Studio 2012 --
cd /d D:\_NX9
set MSVCDir="C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC"
call %MSVCDir%\vcvarsall.bat amd64
set PATH=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE;%PATH%
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
Note that I run it from an NX Command prompt, so that all of my UGII variables are already set.
Also, if you are using the Express version, the name of your executable is probably different. I don't have the express version, so you'll have to find it on your system.