Showing results for 
Search instead for 
Did you mean: 

Creating NX Open application (External)


Hi all, 

I am into application development using C++. I am new to NXOpen. For my next assignment I am looking to creating an application in C++ using NXOpen libraries. The application is supposed to be external to NX environment (as an independent setup and program launcher). Where should I start? I have been reading through the documentation but have never actually worked on NX before. (I have Visual Studio 2010 and NX 8.5 installation)
The application that I am creating will read a set of points from a file and pass to NX or NX session and create a surface in NX. I intend to perform a few more operations on the surface, outside of NX, like creating a mesh. 
I am having trouble in setting up the project. What selection do I need to make to have this application as external? The application need not open the NX viewer. What should the entry point of this application be? 

Thanks for help in advance. 



Re: Creating NX Open application (External)

Siemens Genius Siemens Genius
Siemens Genius

Hi Wilson


C++ is not my favorite NX Open language, i use mainly VB, but setting an external application should be the same.


Why don't you use the Project Creation Wizard in Visual Studio


 File / new Project / other language/Visual C++ / an select the NX8 OPEN WIZARD it will drive by question to the correct setting isn't it?


Hope this Help


Re: Creating NX Open application (External)



Thanks a lot, that was helpful Smiley Happy 

Re: Creating NX Open application (External)

Valued Contributor
Valued Contributor

You may need some help communicating with NX as it does not work in the same manner as most windows applications. 

As far as I'm aware you can't connect to a currently running session from outside NX which is what I'm guessing you mean by "passing" to the NX session.

Your options are:

to run your programme inside NX as an un-compiled journal or as a compiled (and signed) dll.

to create a new nx session that you control from your external application.


This topic has more details

Re: Creating NX Open application (External)


Actually you can connect to a running session using remoting.

Details can be found in the documentation here:

NX Documentation->NX Open->NX Open Programmer's Guide->Execution Methods->Remote Processes
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | KF
Production: [NX8.5.3.3 MP11 64bit] Testing: [NX12.0.0.27 MP1]

Re: Creating NX Open application (External)

Valued Contributor
Valued Contributor

Hi Graham,


(Sorry to hijack the thread Wilson)

Do you have any working examples of this?

The documentation says this is possible but doens't explain how to do it....

Re: Creating NX Open application (External)


I'm mainly developing in Java and use remoting quite a lot to test code from inside Eclipse against a running NX session. Unfortunately I'm no expert in the actual remoting side of things, I just use it. The RMI server (which is what runs inside NX to allow remote connections, at least for Java) was set up by some colleagues.


However, there are .NET and Java examples provided with the NX install:


{NXInstallFolder}\UGOPEN\SampleNXOpenApplications\Java\RemotingExample {NXInstallFolder}\UGOPEN\SampleNXOpenApplications\.NET\RemotingExample


Hopefully these should get you started.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | KF
Production: [NX8.5.3.3 MP11 64bit] Testing: [NX12.0.0.27 MP1]

Re: Creating NX Open application (External)

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

NX comes with some samples to look at. An example for remoting (C#) can be found at:

{NX install dir}\UGOPEN\SampleNXOpenApplications\.NET\RemotingExample


A C++ sample can be found at:

{NX install dir}\UGOPEN\NXOpen

Re: Creating NX Open application (External)

Siemens Phenom Siemens Phenom
Siemens Phenom

The remoting stuff is interesting, and it's sometimes useful. But, since the OP is new to NX/Open programming, I'd recommend staying away from remoting (since he has enough things to learn, already). The situations where remoting is really needed are fairly uncommon, in my experience, and there are simpler alternatives that might be suitable:


If there is already a running NX session, the program can be launched from inside this session by using File-->Execute-->NX Open.


If there is no running NX session, his program can create one, which makes the connection easy.


See the discussion of "Execution Modes" in The NX Open Programmer's Guide.


Re: Creating NX Open application (External)

Valued Contributor
Valued Contributor

For any of you that use .net here's a translated version of the server script:


Option Strict Off
Imports System
Imports System.IO
Imports System.Threading
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Serialization.Formatters
Imports System.Diagnostics

Imports System.Collections

Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.UF

Module Module1
    Const port As Integer = 4567
    Dim theSession As Session
    Dim theUFSession As UFSession

    'The first flag indicates that we are unloading the dll.  The second flag indicates that the service has completed.  This is needed as the 
    'Run and the unload will be run in in two different threads.  We indicate that we that we can are unloading so we can end the while loop
    'and then output a message to the syslog that the service has ended.  However, since we have two threads, we do not want the the unload method to 
    'proceed until the service loop is done processing.
    Dim isUnloaded As Boolean = False
    Dim serviceEnded As Boolean = False
    '  NX Startup
    '      This entry point activates the application at NX startup

    'Will work when complete path of the dll is provided to Environment Variable 

    Function Startup(ByVal args As String()) As Integer


        Return 0

    End Function
    Public Sub DoLog(ByVal s As String)

    End Sub

    Public Sub Start()

        Dim serverThread As Thread = New Thread(New ThreadStart(AddressOf Run))
    End Sub

    ' This method should only peform the following operations:
    '  - Setting up Remoting 
    '  - Obtaining the session
    '  - Exporting the session
    ' If you make other calls especially NXOpen calls that may involve the UI
    ' (such as ListingWindow).  This may put NX in state of an infinite loop.
    ' Calls to the LogFile API are acceptable though.
    Public Sub Run()

        DoLog("In NXOpenRemotingService.Main - getting session")
        theSession = Session.GetSession()
        theUFSession = UFSession.GetUFSession()

            DoLog("Starting NX Service")

            LifetimeServices.LeaseTime = System.TimeSpan.FromDays(10000)

            Dim provider As SoapServerFormatterSinkProvider = New SoapServerFormatterSinkProvider()
            provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full

            ' Create the IDictionary to set the port on the channel instance.

            Dim props As New Hashtable
            'IDictionary(props = New Hashtable())
            Dim lnkprov As System.Runtime.Remoting.Channels.IServerChannelSinkProvider

            props.Add("port", port)
            ' Create a new http channel with the given provider and properties
            ChannelServices.RegisterChannel(New HttpChannel(props, lnkprov, provider), False)

            DoLog("Exporting Session object")
            RemotingServices.Marshal(theSession, "NXOpenSession")

            DoLog("Exporting UFSession Object")
            RemotingServices.Marshal(theUFSession, "UFSession")

            DoLog("NX Service started on port " & port)

        Catch e As Exception

        End Try
        While (isUnloaded = False)

        End While

        DoLog("SERVICE ENDED!!!")
        serviceEnded = True
    End Sub

    Public Sub UnloadLibrary(ByVal arg As String)

        isUnloaded = True
        While serviceEnded = False

        End While

        DoLog("Disconnecting Session object")

        DoLog("Disconnecting UFSession Object")
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image explicitly, via an unload dialog
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

 This code is intended to be run as a user_startup which if set correctly in your NX environment will launch the dll when an nx session is started.