NX How to detect which Button is Pressed passed with NX API

2021-10-06T23:27:14Z
NX Open NX System Administration

Summary


Details

Sometimes the same .DLL is called by several different custom buttons. This DLL may need to behave differently depending on which button launched it.



Solution

Sometimes the same .DLL is called by several different custom buttons. This DLL may need to behave differently depending on which button launched it.


Note:


To make this work with the Ribbon toolbars, first define the buttons and their actions in a .MEN file. Then HIDE the menu on which the custom buttons reside. Then in the .RTB file, specify the .MEN buttons.


Different labels are used in the .RTB file. These will take precedence when the .RTB is displayed. I.E. The labels assigned in the .MEN file will not be displayed. The button label define in the .MEN file will be the value reported by decide_button.dll.


The .MEN and .RTB files go in a valid 'startup' folder.


The .DLL goes in a valid "application" folder. When one of the buttons is pushed, the DLL will correctly report what button was pushed.


Example .MEN file:


VERSION 120


EDIT UG_GATEWAY_MAIN_MENUBAR


AFTER UG_APP_MODELING 
 CASCADE_BUTTON NEW_MENU 
 LABEL Report_button 
END_OF_AFTER


MENU Report_button


BUTTON CUSTOM_BUTTON_1 
LABEL CUSTOM_BUTTON_1 
ACTIONS decide_button.dll


BUTTON CUSTOM_BUTTON_2 
LABEL CUSTOM_BUTTON_2 
ACTIONS decide_button.dll


BUTTON CUSTOM_BUTTON_3 
LABEL CUSTOM_BUTTON_3 
ACTIONS decide_button.dll


BUTTON CUSTOM_BUTTON_4 
LABEL CUSTOM_BUTTON_4 
ACTIONS decide_button.dll


END_OF_MENU


===========================================


Example .rtb file:



! Report_button Ribbon Tab 
!


TITLE Report_button 
VERSION 170


BUTTON CUSTOM_BUTTON_1 
LABEL Report_button1


BUTTON CUSTOM_BUTTON_2 
LABEL Report_button2


BUTTON CUSTOM_BUTTON_3 
LABEL Report_button3


BUTTON CUSTOM_BUTTON_3 
LABEL Report_button4


===========================================


Example VB code to be compiled into decide_button.dll:


Option Strict Off 
Imports System 
Imports NXOpen


Module report_button_name_from_which_dll_was_launched


 Dim s As Session = Session.GetSession() 
 Dim lw As ListingWindow = s.ListingWindow


 Sub Main(Args() As String)


 If (Args(0).Length > 0) Then 
 MsgBox("Called from: " & Args(0)) 
 Else 
 MsgBox("This does not appear to have been launched from a custom button.") 
 End If


 End Sub


 Public Function GetUnloadOption(ByVal dummy As String) As Integer


 Return Session.LibraryUnloadOption.Immediately


 End Function


End Module



Notes and References


Hardware/Software Configuration

Platform: AMD64
OS: window
OS Version: 764SP1
Product: NX
Application: SYSENG
Version: V11.0
Function: NXOPEN

Ref: 002-7008263

KB Article ID# PL7008263

Contents

SummaryDetails

Associated Components

Block/UI Interface Stylers Knowledge Fusion Menuscript NX Open - All Languages NX Open Python Open for C/C++ Open for CAE Open for GRIP Open for Java Pre-NX6 UI Styler SNAP UDO