Cancel
Showing results for 
Search instead for 
Did you mean: 

How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Pioneer
Pioneer

I'm currently optimizing a batch DLL for our NX 7.5 / Teamcenter 4Tier environment to render product images in a non interactive session.

I'm currently launching the DLL by setting the environment variable USER_STARTUP to my DLL. This DLL contains a "Public Function Startup()", which is called directly if I start NX via command line "ugraf.exe". By the fact that the library has to operate in a Teamcenter framework, I launch NX via the command line "ugraf.exe -pim=yes -u=*** -p=*** -g=***". The library is operating like exepected. It is loading a part from Teamcenter, setting a few appearance paratemers, running the High Quality Image render and saving the file.

The issue occures when it comes to the point for closing the entire NX session. If I use the simple "Return 0" line in the Startup() function, the NX session will be left in the "No Part" state. If I use the "System.Environment.Exit(0)" command, the NX session will not be terminated in the 4Tier scenario. Instead of that an error message appears. The same line "System.Environment.Exit(0)" works fine in a native, non-Teamcenter session. Also a previously included "ufs.ugmgr.Terminate()" does not solves this issue. By the fact that I need a few rendering techniques, which are available in a full ugraf.exe session only, a possible run_journal scenario will not be feasible for this case. Up to now I use a workaround and terminate the session with a -key=CloseSession.macro script addon. But It fails more often when I want to run it on different computers.

 

What is the most accurate way to launch and terminate an ugraf.exe session with Teamcenter 4 Tier connection and running a dll directly?

 

Regards

 

Matthias

5 REPLIES

Re: How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Esteemed Contributor
Esteemed Contributor

How about the following options?

  • send the main window the close message
  • send the main ugraf process the terminate message

I would first go with the Window.

 

In addition I would make sure to close all parts before closing the window.

 

BTW, UF_UGMGR_terminate is no longer used since UGII v12, where NX 7.5 is UGII v25.5

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Pioneer
Pioneer

Hello Stefan,

 

Thanks for your response.

 

But up to now I was not able to adopt your proposal. I do not have any idea for the code lines to close the main window or the ugraf process. I was not able to determine the related commands within the NXOpen Namespace. I have also tried to implement a shell command, which is running the “taskill” command. The issue is either that the application is hard killed with an error code (TASKKILL method) or an “NX Component error” appears if I run the “System.Environment.Exit(0)" command within the “Startup()” function for a Teamcenter based 4Tier session. Can you provide a code skeleton of such a safety closing .dll application, which can be launched with the USER_STARTUP environment variable on the ugraf.exe command?

 

Regards

 

Matthias

 

 

Re: How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Esteemed Contributor
Esteemed Contributor

TASKKILL is not meant to gracefully terminate a process, it just kills it and that is not good at all, since there will be a dangling session at the Teamcenter server left over.

 

You would need to get the Windows handle of the NX main window and send it the WM_CLOSE message, but make sure to first close all parts. so you don't get a save notice window.

 

I never had to close an interactive session, I was always able to run things as a batch process.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Pioneer
Pioneer

Hello Stefan,

 

Thank you very much

 

With your hint about the WM_CLOSE message I embedded the following code, which works now well for me and closes the NX session carefully without an error code. Like mentioned, the rest of the code leads into a situation where my UGRAF.EXE session stays in the "No-Part" / "Teamcenter 4Tier Manager" state. To finalize the NX session carefully and get controll back to the HTCondor GRID system, which is the initial driver for this batch command, I included:

 

In the "Module NXJournal" section the wollowing two declarations:

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Const WM_CLOSE as long = &H10

 

In the "Public Function Startup()  As Integer" section, which is called directly after the UGRAF.EXE start and the USER_STARTUP environment variable definition:

  ' ----------------------------------------------
  ' Get the handle of the parent window
  ' ----------------------------------------------
  Dim ParWinHndl as integer
  ParWinHndl = NXOpenUI.FormUtilities.GetDefaultParentWindowHandle()
  ' ----------------------------------------------
  ' Send the WM_CLOSE Message
  ' ----------------------------------------------
  SendMessage(ParWinHndl, WM_CLOSE, 0, 0)

 

These adjustments are now closing my NX session carefully when the .dll library was executed.

 

Regards

 

Matthias

Re: How to terminate NX 7.5 - Teamcenter 4 Tier session from .NET DLL?

Esteemed Contributor
Esteemed Contributor

I would always send a message to the window, since this is how the bare-bones Windows API works.

 

I don't know what the remarks section for application.exit says, but there might be hints as well.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community