//------------------------------------------------------------------------------ // Callback Name: PrintMenu // Prints a note and a description of the menu to the listing window. //------------------------------------------------------------------------------ public static void PrintMenu(NXOpen.MenuBar.ContextMenu menu, NXOpen.MenuBar.ContextMenuProperties props, string prefix = " ") { int numMenuEntries = menu.NumberOfEntries; for (int i = 0; i < numMenuEntries; i++) { NXOpen.MenuBar.ContextMenuEntry entry = menu.GetEntry(i); if (entry.EntryType == NXOpen.MenuBar.ContextMenuEntry.Type.Separator) { lw.WriteLine(prefix + i + " = --------------------"); } else { lw.WriteLine(prefix + i + " = " + entry.Label); } // If this entry is a submenu, write out its submenu as well. if (entry.EntryType == NXOpen.MenuBar.ContextMenuEntry.Type.Submenu) { PrintMenu(menu.GetSubmenu(i), props, prefix + " "); } } }
//------------------------------------------------------------------------------ // 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); }