NXKnowledge

NX Open Programmer's Guide > Execution Methods > Programs, Journals, or Callbacks from New Menu Items > Callback Registration for NX Open for .NET

Callback Registration for NX Open for .NET

The AddMenuAction method (on MenuBarManager) registers a callback with NX. The name passed must match the string used as the ACTIONS value in the menu file (e.g. "my_app_hello", "my_app_goodbye"). The example (hello_goodbye.vb) registers both callbacks in the Startup method; after building, hello_goodbye.dll goes in the startup folder alongside a matching example menu file.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Module Module1
    ' HelloCB - Opens a message box that says "Hello"
    Public Function HelloCB(ByVal buttonEvent As NXOpen.MenuBar.MenuButtonEvent) As NXOpen.MenuBar.MenuBarManager.CallbackStatus
        MsgBox("Hello")
        HelloCB = 0
    End Function

    ' GoodbyeCB - Opens a message box that says "Goodbye"
    Public Function GoodbyeCB(ByVal buttonEvent As NXOpen.MenuBar.MenuButtonEvent) As NXOpen.MenuBar.MenuBarManager.CallbackStatus
        MsgBox("Goodbye")
        GoodbyeCB = 0
    End Function

    ' NX Startup - activates the application at NX startup
    Function Startup(ByVal args As String()) As Integer
        Dim theUI As UI = GetUI()
        Dim theSession As Session = Session.GetSession
        theUI.MenuBarManager.AddMenuAction("my_app_hello", AddressOf HelloCB)
        theUI.MenuBarManager.AddMenuAction("my_app_goodbye", AddressOf GoodbyeCB)
        Return 0
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        ' Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
    End Function
End Module

Related Topics

  • Programs, Journals, or Callbacks from New Menu Items — Overview
  • Introduction to Menu Files
  • Executing Programs
  • Executing Journals
  • Executing Callbacks (Menu Event Handlers)
  • Callback Registration for NX Open for C++
  • Callback Registration for NX Open for Java

Source: https://docs.sw.siemens.com/en-US/doc/209349590/PL20220512394070742.nxopen_prog_guide/new_menu_net · retrieved Tue Jul 07 2026 00:00:00 GMT+0000 (Coordinated Universal Time)