//------------------------------------------------------------------------------ // Callback Name: CustomizeMenu // Executed when a customizable context menu is about to be displayed. //------------------------------------------------------------------------------ public static int CustomizeMenu(NXOpen.MenuBar.ContextMenu menu, NXOpen.MenuBar.ContextMenuProperties props) { // When in the Modeling application, hide the Delete button in the Graphics Window context menu. int moduleId; theUFSession.UF.AskApplicationModule(out moduleId); if (moduleId == UFConstants.UF_APP_MODELING && string.Equals(props.Location, "GraphicsWindow")) { if (menu.HasEntryWithName("UG_EDIT_DELETE")) { NXOpen.MenuBar.ContextMenuEntry deleteMenuEntry = menu.GetEntryWithName("UG_EDIT_DELETE"); menu.HideEntry(deleteMenuEntry); } } // Find the last visible push-button entry on the menu NXOpen.MenuBar.ContextMenuEntry entry = null; int numMenuEntries = menu.NumberOfEntries; for (int i = 0; i < numMenuEntries; i++) { NXOpen.MenuBar.ContextMenuEntry entry2 = menu.GetEntry(i); // Identify the last menu entry which is something that can be // activated and which is visible and sensitive. if (entry2.EntryType == NXOpen.MenuBar.ContextMenuEntry.Type.PushButton && !entry2.IsHidden && entry2.IsSensitive) { entry = entry2; } } // Set identified entry as the default and move to the top of the menu. if (entry != null) { menu.SetDefaultEntry(entry); menu.MoveEntry(entry, 0); } // Add an additional menu button for a specific context. if (string.Equals(props.Context, "Features.Cylinder")) { // Retrieve an NX menu button NXOpen.MenuBar.MenuButton newButton = theUI.MenuBarManager.GetButtonFromName("UG_PREFERENCES_VISUALIZATION"); NXOpen.MenuBar.ContextMenu subMenu = menu.AddSubmenu("Custom", -1); subMenu.AddMenuButton(newButton, -1); } // Open the Print the Information window and print the menu. lw.Open(); lw.WriteLine("Customize menu for " + props.Context + " in " + props.Location); PrintMenu(menu, props); return(0); }
//------------------------------------------------------------------------------ // Callback Name: PrintButtonIdCB // This is a callback method associated with SAMPLE_CSHARP_APP__action1 action button. // This will get executed whenever 'Print Button ID' is selected from the // 'Sample C Sharp' menu. // Given a button name (such as SAMPLE_CSHARP_APP_BUTTON1) from the user, the // input button's id gets printed to the listing window. //------------------------------------------------------------------------------ public static NXOpen.MenuBar.MenuBarManager.CallbackStatus PrintButtonIdCB(NXOpen.MenuBar.MenuButtonEvent buttonEvent) { // ---- Enter your callback code here ----- lw.Open(); lw.WriteLine(" "); lw.WriteLine("Inside PrintButtonIdCB Callback:"); String buttonName = buttonEvent.ActiveButton.ButtonName; buttonName = Interaction.InputBox("Enter name of button you wish to query", "Print Button Id", buttonName, 100, 100); NXOpen.MenuBar.MenuButton myButton = theUI.MenuBarManager.GetButtonFromName(buttonName); if (myButton == null) { lw.WriteLine(" " + buttonName + " button not found"); } else { lw.WriteLine(" Button Id for " + buttonName + ": " + myButton.ButtonId); } lw.WriteLine(" "); return(NXOpen.MenuBar.MenuBarManager.CallbackStatus.Continue); }