Yes you can launch the NX11 from your visual studio for VB / C#.NET program. Follow the below steps to acheive that:
Open your DLL or EXE project.
On the properties for the project (Right click on Project -> Properties), go to the Debug tab.
Choose Start external program and give the path (C:\apps\Siemens\NX11\NXBIN\ugraf.exe) of the external program that will call your DLL, along with any command-line arguments you may need to supply, and the working directory if that's relevant.
Save the project.
Set breakpoints in your code where you want them.
Press F5 to start debugging. (At this point, your breakpoints will say that they won't be hit because the symbols aren't loaded. Don't worry about that for now.)
Run the Debug DLL in your NX session window as normally executing the application like CTRL + U.
The application will stop at your breakpoint as you needed.
I'm not aware of a api to start NX through vb code.
What Quest_mani suggests is the debugging of your NX code.
NX does have the possibility though to run in batch, with a specified journal (.vb).
You could launch NX in batch from your program through the new process() vb functionality (see below for example on calling the solver externally from .vb code) and wait for it to finish.
You can find more on the forum on how to run NX in batch.
'call solver externally Dim p as Process = new process() Dim pi as ProcessStartInfo = new ProcessStartInfo() pi.Arguments = " " + "/C" + " " + """C:\Program Files\Siemens\NX 10.0\NXNASTRAN\bin\nastran64.exe"" H:\FEM\13173\models\total_model_sim-solution_1.dat PROG=DESK" pi.FileName="cmd.exe" p.startinfo=pi 'Start the solver using the command line syntax as defined p.start() 'wait for the solver to finish p.WaitForExit()
It's not exactly what you were looking for, but perhaps this might be a workaround.
Thanks for the reply.
The thing which i am trying to achieve is,
A .exe on run by the user will open a form which allows user to browse folder containing NX files.
on click of Run button, code will launch NX ,opens NX files,reads some attributes and creates exccel report and exist.
code written should be executed like this,
lunch NX manually, select exe from NX and form is displayed and so on
User has to run any code through NX. I need to remove this step.
Do you any idea?
What about writing your .exe such that it asks the user to select the files (so completely outside NX).
After the user has selected the files, (and only then) you start NX externally in batch mode with the files as arguments. The code in the exe waits till NX has finished
call "C:\Program Files\Siemens\NX 10.0\UGII\run_journal.exe" "C:\MyJournal.vb" -args Argument1 Argument2 Argument3
MyJournal.vb contains the functions to be executed in NX, and Argument1, Argument2,... can be the filenames.
MyJournal.vb writes data to a file (eg. MyDataFromNX.txt) which is then read again by the .exe which passes the data from MyDataFromNX.txt to your excel file.
I done through launching process,where i will ask user to locate NX exe and launch given path.
This will work as i needn't to hardcode where NX is install.
I have some study about running NX from batch mode and controlling it.
Here, I can run a journal file which opens a model changes some expressions and goes to simulation , updating fem and running analysis. I have another journal which exports analysis results to excel file.
set base=C:\Program Files\Siemens\NX 10.0 set base_dir=%base:"=% if "%base_dir:~-1%" == "\" set base_dir=%base_dir:~0,-1% set UGII_BASE_DIR=%base_dir% set UGII_ROOT_DIR=%base_dir%\UGII\ set PATH=%base_dir%\ugii;%PATH% call "c:\Program Files\Siemens\Nx 10.0\ugopen\ufvars.bat" "%base_dir%" if "%DISPLAY%" == "" set DISPLAY=LOCALPC:0.0 cd /d C:\Work\duzenli_dosyalar run_journal "Change_exp_run.vb"
Also, I control these files from excel macro ;
Sub ANALIZ() Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") wsh.Run ThisWorkbook.Path & Application.PathSeparator & "ugiicmd_analiz.bat", 1, True Application.Wait (Now + TimeValue("00:00:5")) For a = True To False Set ds = CreateObject("Scripting.FileSystemObject") a = ds.FileExists("C:\Work\duzenli_dosyalar\mil_parametrik_simple_geometry_sim1-solution_1.plt") If a = True Then Application.Wait (Now + TimeValue("00:00:01")) Else Dim wsh2 As Object Set wsh2 = VBA.CreateObject("WScript.Shell") wsh2.Run ThisWorkbook.Path & Application.PathSeparator & "ugiicmd_result.bat", 1, True End If Next Workbooks.Open Filename:="C:\Work\Duzenli_Dosyalar\Results.xlsx" sonuc = Range("A2") Windows("Work_Excel.xlsm").Activate Sheets("Mil_Parametreler").Range("B1").Value = sonuc Windows("Results.xlsx").Activate ActiveWindow.Close ActiveWorkbook.Save End Sub
This study may help you , I hope.
Best regards ,
Hi @Tevfik-Uzun ,
Can you explain me why you call this file ?
call "c:\Program Files\Siemens\Nx 10.0\ugopen\ufvars.bat" "%base_dir%"
if "%DISPLAY%" == "" set DISPLAY=LOCALPC:0.0
and not just :
Production: NX22.214.171.124,VERICUT 8.1.2
Development: Tcl/Tk, Gnuplot