Cancel
Showing results for 
Search instead for 
Did you mean: 

Launch NX 11 from VB.net or C#

Pioneer
Pioneer

Hello All,

 

Can we launch NX 11 from Visual studio ?,like we launch Excel as createobject (through API).

Does it has exposed API for creating session.

 

Any help would be appreciated.

 

Thanks

GNR

13 REPLIES

Re: Launch NX 11 from VB.net or C#

PLM World Member Legend PLM World Member Legend
PLM World Member Legend

Yes you can launch the NX11 from your visual studio for VB / C#.NET program. Follow the below steps to acheive that:

 

  1. Open your DLL or EXE project.

  2. On the properties for the project (Right click on Project -> Properties), go to the Debug tab.

  3. 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.

  4. Save the project.

  5. Set breakpoints in your code where you want them.

  6. 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.)

  7. 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.

Re: Launch NX 11 from VB.net or C#

Pioneer
Pioneer

Thanks for the reply.

 

But i need to create session through code.

I guess there is no api exposed, so what you suggested may workout.

 

 

Thanks

Guru

Re: Launch NX 11 from VB.net or C#

Genius
Genius

 

Hello GNR,

 

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.

 

Regards,

Frederik

Re: Launch NX 11 from VB.net or C#

Pioneer
Pioneer

Hi Frederik,

 

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.

 

So far, 

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?

 

Thanks

GNR

 

Re: Launch NX 11 from VB.net or C#

Genius
Genius

Hello GNR,

 

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.

 

Regards,

Frederik

Re: Launch NX 11 from VB.net or C#

Pioneer
Pioneer

Frederik,

 

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.

 

Thanks

GNR

 

 

Re: Launch NX 11 from VB.net or C#

Creator
Creator

Hi GNR, 

 

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 , 

Tevfik

 

Re: Launch NX 11 from VB.net or C#

Pioneer
Pioneer

Hi Tevfik,

Thanks for the reply.

This will help me lot.

 

Thanks

GNR

Re: Launch NX 11 from VB.net or C#

Legend
Legend

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 :

run_journal "Change_exp_run.vb"

Thank you

 

Production: NX11.0.2.7,VERICUT 8.1.2
Development: Tcl/Tk, Gnuplot
www.adgroupe.com