예제 #1
0
        /**
         *   Callback method that gets invoked when a custom menu
         *   is selected.
         */
        public int CustomPopupMenuInvokedCallback()
        {
            // m_UI.NXMessageBox.Show("MenuCreator", NXOpen.NXMessageBox.DialogType.Information, "CAME HERE");
            //
            // The invoked menu item can be queried. Menu Item can be again queried for
            // ID and name.
            //
            CustomPopupMenuItem menuItem = m_MenuHandler.GetInvokedCommand();

            //
            // The List of object selected in the Tree  can be queried.
            //
            TreeListNode[] treeListNode;
            m_MenuHandler.GetSelectedNodes(out treeListNode);

            if (treeListNode == null || treeListNode.Length == 0)
            {
                // No selected nodes
                return(0);
            }

            string[] uids      = new string[treeListNode.Length];
            string[] nodeTypes = new string[treeListNode.Length];
            for (int i = 0; i < treeListNode.Length; i++)
            {
                //
                // For each Object returned in the List the UID and Object Type can be queried. Need
                // to cast the object to NXOpen::TcModelObjectItem before quering the UID and Type.
                //
                String uid  = ((NXOpen.PDM.PdmNavigatorNode)treeListNode[i]).GetUid();
                String type = ((NXOpen.PDM.PdmNavigatorNode)treeListNode[i]).GetNodeType();
                uids[i]      = uid;
                nodeTypes[i] = type;
            }
            ListingWindow lw = m_Session.ListingWindow;

            lw.Open();
            lw.WriteLine(" ");
            lw.WriteLine("Inside popupMenuInvokedCallBack Callback ");
            lw.WriteLine("COMMAND NAME: ");
            lw.WriteLine(menuItem.GetName());
            lw.WriteLine("SELECTED NODE UIDS: ");
            for (int i = 0; i < uids.Length; i++)
            {
                lw.WriteLine(uids[i]);
            }

            lw.WriteLine("SELECTED NODE TYPES: ");
            for (int i = 0; i < nodeTypes.Length; i++)
            {
                lw.WriteLine(nodeTypes[i]);
            }


            if (menuItem.GetName().Equals("Revise"))
            {
                lw.WriteLine("NEW REVISION ID: ");
                lw.WriteLine("Implement Teamcenter user exits function to show output");
                //
                // Uncomment code below after implementing the user exits method
                //
                // int errorCode = 0;
                // string name = null;
                // m_ugMgr.InvokePdmServer(2, uids[0], out errorCode, out name);
                // lw.WriteLine(name);
            }
            else
            {
                lw.WriteLine("SELECTED NODE NAMES: ");
                lw.WriteLine("Implement Teamcenter user exits function to show output");
                //
                // Uncomment code below after implementing the user exits method
                //

                // for (int i = 0; i < uids.Length; i++)
                // {
                //     int errorCode = 0;
                //     string name = null;
                //     m_ugMgr.InvokePdmServer(1, uids[i], out errorCode, out name);
                //     lw.WriteLine(name);
                // }
            }

            return(0);
        }
예제 #2
0
        /**
         *   Callback method to add custom menus/submenus
         *
         */
        public int AddCustomPopupMenuCallback()
        {
            StringBuilder message = new StringBuilder();

            try
            {
                //
                // The List of object selected in the Tree  can be queried.
                //
                TreeListNode[] treeListNode;
                m_MenuHandler.GetSelectedNodes(out treeListNode);

                //
                // The selected object(s) can be queried. Following is an example of using
                // querying selected objects.
                //
                if (treeListNode != null && treeListNode.Length > 0)
                {
                    message.Append(" The Following Objects were selected :");
                    message.Append("\n");
                    for (int i = 0; i < treeListNode.Length; ++i)
                    {
                        if (treeListNode[i] is NXOpen.PDM.PdmNavigatorNode)
                        {
                            String uid = ((NXOpen.PDM.PdmNavigatorNode)treeListNode[i]).GetUid();
                            message.Append(" UID :");
                            message.Append(uid);
                            message.Append("\n");

                            String type = ((NXOpen.PDM.PdmNavigatorNode)treeListNode[i]).GetNodeType();
                            message.Append(" Type :");
                            message.Append(type);
                            message.Append("\n");
                        }
                    }
                }

                //
                // Add the Top Level Menus/Separators. Top level menus/menu items/seperators
                // must be added by calling menu handler. Subsequent sublevel menus/menu items/seperators
                // can be added by calling add methods on the corresponding parent menu/submenu.
                //
                m_MenuHandler.AddMenuSeparator();
                CustomPopupMenuItem itemMM1 = m_MenuHandler.AddMenuItem(1, "Main Menu 1");
                CustomPopupMenu     menuMM2 = m_MenuHandler.AddMenu(2, "Main Menu 2");

                CustomPopupMenuItem itemMM3 = m_MenuHandler.AddMenuItem(6, "Revise");

                if ((treeListNode.Length == 1) &&
                    (treeListNode[0] is NXOpen.PDM.PdmNavigatorNode) &&
                    ((NXOpen.PDM.PdmNavigatorNode)treeListNode[0]).GetNodeType().Equals("ItemRevision"))
                {
                    //
                    // Create an new menu only when there is 1 selection and the selection is ItemRevision
                    //
                    CustomPopupMenuItem itemMM4 = m_MenuHandler.AddMenuItem(7, "Main Menu 3");
                }
                else
                {
                    // Code below will show the number of selection objects and the object type of the
                    // first selection

                    message.Append(treeListNode.Length);
                    message.Append("\n");
                    if (treeListNode[0] is NXOpen.PDM.PdmNavigatorNode)
                    {
                        message.Append(((NXOpen.PDM.PdmNavigatorNode)treeListNode[0]).GetNodeType());
                        message.Append("\n");
                    }

                    // Disable the menu when multiple selection and for any selection object which is
                    // not item revision
                    itemMM3.SetDisabled();
                }

                //
                // Add the First Level Menus/Separators to "Main Menu 2"
                //
                CustomPopupMenuItem subMenuSM21 = menuMM2.AddMenuItem(3, "Sub Menu 2-1");
                menuMM2.AddMenuSeparator();
                CustomPopupMenu subMenuSM22 = menuMM2.AddMenu(4, "Sub Menu 2-2");

                //
                // Add Second Level Menu to "Sub Menu 2-2"
                //
                CustomPopupMenuItem subMenuSM221 = subMenuSM22.AddMenuItem(5, "Sub Menu 2-2-1");
                // Any menu/submenu/menuItem can be disabled by calling SetDisabled method
                subMenuSM221.SetDisabled();

                // m_UI.NXMessageBox.Show("MenuCreator", NXOpen.NXMessageBox.DialogType.Information, message.ToString());
            }
            catch (NXException ex)
            {
                m_UI.NXMessageBox.Show("MenuCreator", NXOpen.NXMessageBox.DialogType.Error, ex.Message);
            }
            return(0);
        }