示例#1
0
        public static RibbonPanelSource AddNewPanel(
            this RibbonTabSource instance,
            string name,
            string text = null)
        {
            if (text == null)
            {
                text = name;
            }

            var ribbonRoot        = instance.CustomizationSection.MenuGroup.RibbonRoot;
            var panels            = ribbonRoot.RibbonPanelSources;
            var id                = "pnl" + name;
            var ribbonPanelSource = new RibbonPanelSource(ribbonRoot);

            ribbonPanelSource.Name      = name;
            ribbonPanelSource.Text      = text;
            ribbonPanelSource.Id        = id;
            ribbonPanelSource.ElementID = id;

            panels.Add(ribbonPanelSource);

            var ribbonPanelSourceReference = new RibbonPanelSourceReference(instance);

            ribbonPanelSourceReference.PanelId = ribbonPanelSource.ElementID;

            instance.Items.Add(ribbonPanelSourceReference);

            return(ribbonPanelSource);
        }
示例#2
0
        public static RibbonPanelSource AddRibbonPanel(string tabAlias, string panelAlias, string panelText)
        {
            var        fileName   = Application.GetSystemVariable("MENUNAME") as string;
            var        custSect   = new CustomizationSection(fileName);
            RibbonRoot ribbonRoot = custSect.MenuGroup.RibbonRoot;

            RibbonPanelSource ribbonPanel = ribbonRoot.FindPanelWithAlias(panelAlias);

            if (ribbonPanel != null)
            {
                return(null);
            }

            ribbonPanel = new RibbonPanelSource(ribbonRoot);
            ribbonPanel.Aliases.Add(panelAlias);
            ribbonPanel.Name = panelAlias;
            ribbonPanel.Text = panelText;
            ribbonPanel.Items.Clear();
            ribbonRoot.RibbonPanelSources.Add(ribbonPanel);

            RibbonTabSource tab      = ribbonRoot.FindTabWithAlias(tabAlias);
            var             panelRef = new RibbonPanelSourceReference(tab);

            panelRef.PanelId = ribbonPanel.ElementID;
            tab.Items.Add(panelRef);

            return(ribbonPanel);
        }
示例#3
0
        /// <summary>从局部Cui文件中加载选项卡(必须先添加对 AcCui.dll 的引用) </summary>
        /// <param name="strCuipath"></param>
        /// <remarks>
        /// 使用cuix文件添加对应 RibbonButton
        /// 先判断是否添加配置cuix
        /// 将配置cuix中的配置功能项添加到acad.cuix中的功能区
        /// 刷新工作空间的功能区命令
        /// </remarks>
        public static void AddRibbonButtonByCustomCui(string strCuipath)
        {
            string mainCuiFile = (string)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("MENUNAME");

            mainCuiFile += ".cuix";
            CustomizationSection     csLoad = new CustomizationSection(mainCuiFile);
            PartialCuiFileCollection pPartialCuiFileCollection = csLoad.PartialCuiFiles;

            if (pPartialCuiFileCollection.Contains("mycui.cuix"))
            {
                MessageBox.Show("已加载插件!");
                Autodesk.AutoCAD.ApplicationServices.Application.UnloadPartialMenu(strCuipath);
                //return;
            }

            bool isOK = Autodesk.AutoCAD.ApplicationServices.Application.LoadPartialMenu(strCuipath);

            //加载自定义cui
            if (!isOK)
            {
                MessageBox.Show("加载自定义配置文件失败!");
                return;
            }

            //加载CUI
            //Application.QuitWillStart += new EventHandler(Application_BeginQuit);
            //Application.BeginQuit += new EventHandler(Application_BeginQuit);
            //Autodesk.Windows.ComponentManager.ApplicationMenu.Opening += new EventHandler<EventArgs>(ApplicationMenu_Opening);

            CustomizationSection     cs       = new CustomizationSection(mainCuiFile);
            PartialCuiFileCollection cuiFiles = cs.PartialCuiFiles;

            //acad.cuix配置文件
            if (cuiFiles.Contains("mycui.cuix"))
            {
                //将my.cuix文件中的配置按钮写入acad.cuix文件中去
                string strPartialCui          = cuiFiles.GetFileNameByIndex(cuiFiles.IndexOf("mycui.cuix"));
                CustomizationSection csCustom = new CustomizationSection(strPartialCui);
                var pRibbonPanelSource        = csCustom.MenuGroup.RibbonRoot.FindPanel("RBNU_191_C0DED");
                //自定义panel中的ElementID
                var pCloneRibbonPanelSource =
                    pRibbonPanelSource.Clone() as Autodesk.AutoCAD.Customization.RibbonPanelSource;
                cs.MenuGroup.RibbonRoot.RibbonPanelSources.Add(pCloneRibbonPanelSource);

                RibbonTabSource pRibbonTableSource2 = cs.MenuGroup.RibbonRoot.FindTab("RBN_00012112");
                //插件Tab的ElementID
                RibbonPanelSourceReference pRibbonPanelSourceRefrence =
                    new RibbonPanelSourceReference(pRibbonTableSource2);
                //这一步ID一定要赋值
                pRibbonPanelSourceRefrence.PanelId = pCloneRibbonPanelSource.ElementID;
                pRibbonTableSource2.Items.Add(pRibbonPanelSourceRefrence);

                cs.Save();
                Autodesk.AutoCAD.ApplicationServices.Application.ReloadAllMenus(); //否则不现实按钮
            }
        }
示例#4
0
 private static void RemoveRibbonPanelSourceReference(RibbonTabSource tab, string elementID)
 {
     if (tab != null)
     {
         foreach (RibbonPanelSourceReference item in tab.Items)
         {
             if (item.PanelId == elementID)
             {
                 tab.Items.Remove(item);
                 return;
             }
         }
     }
     tab.SetIsModified();
 }
示例#5
0
        public static bool RemoveRibbonPanel(string tabAlias, string panelAlias, PluginCommandButton[] buttons)
        {
            var        fileName    = Application.GetSystemVariable("MENUNAME") as string;
            var        custSection = new CustomizationSection(fileName);
            RibbonRoot ribbonRoot  = custSection.MenuGroup.RibbonRoot;

            RibbonPanelSource ribbonPanel = ribbonRoot.FindPanelWithAlias(panelAlias);

            if (ribbonPanel == null)
            {
                return(false);
            }

            // Remove command and split buttons,  and panel row
            var row         = ribbonPanel.Items[0] as RibbonRow;
            var splitButton = row.Items[0] as RibbonSplitButton;

            splitButton.Items.Clear();
            splitButton.SetIsModified();

            row.Items.Clear();
            row.SetIsModified();

            ribbonPanel.Items.Clear();
            ribbonPanel.SetIsModified();

            // Remove the reference to panel from Add-ins tab
            RibbonTabSource tab = ribbonRoot.FindTabWithAlias(tabAlias);

            RemoveRibbonPanelSourceReference(tab, ribbonPanel.ElementID);

            RemoveMacrosOfCommandButtons(custSection, buttons);

            ribbonRoot.RibbonPanelSources.Remove(ribbonPanel);
            ribbonRoot.SetIsModified();

            custSection.Save();

            return(true);
        }
示例#6
0
        public static RibbonTabSource AddNewTab(
            this CustomizationSection instance,
            string name,
            string text = null)
        {
            if (text == null)
            {
                text = name;
            }

            var ribbonRoot      = instance.MenuGroup.RibbonRoot;
            var id              = "tab" + name;
            var ribbonTabSource = new RibbonTabSource(ribbonRoot);

            ribbonTabSource.Name      = name;
            ribbonTabSource.Text      = text;
            ribbonTabSource.Id        = id;
            ribbonTabSource.ElementID = id;

            ribbonRoot.RibbonTabSources.Add(ribbonTabSource);

            return(ribbonTabSource);
        }
示例#7
0
        public static void CreateRibbonTabAndPanel(CustomizationSection cs, string toWorkspace, string tabName, string panelName)
        {
            RibbonRoot root = cs.MenuGroup.RibbonRoot;
            RibbonPanelSourceCollection panels = root.RibbonPanelSources;

            //Create The Ribbon Button
            MacroGroup macroGroup = new MacroGroup("MM19macroGroup", cs.MenuGroup);
            MenuMacro  macroLine  = macroGroup.CreateMenuMacro("TestLine",
                                                               "^C^C_Line",
                                                               "ID_MyLineCmd",
                                                               "My Line help",
                                                               MacroType.Any,
                                                               "RCDATA_16_LINE",
                                                               "RCDATA_32_LINE",
                                                               "My Test Line");

            //Create the ribbon panel source and add it to the ribbon panel source collection
            RibbonPanelSource panelSrc = new RibbonPanelSource(root);

            panelSrc.Text      = panelSrc.Name = panelName;
            panelSrc.ElementID = panelSrc.Id = panelName + "_PanelSourceID";
            panels.Add(panelSrc);



            //Create the ribbon tab source and add it to the ribbon tab source collection
            RibbonTabSource tabSrc = new RibbonTabSource(root);

            tabSrc.Name      = tabSrc.Text = tabName;
            tabSrc.ElementID = tabSrc.Id = tabName + "_TabSourceID";
            root.RibbonTabSources.Add(tabSrc);

            //Create the ribbon panel source reference and add it to the ribbon panel source reference collection
            RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(tabSrc)
            {
                PanelId = panelSrc.ElementID
            };

            tabSrc.Items.Add(ribPanelSourceRef);

            // Create a ribbon row
            RibbonRow ribRow = new RibbonRow(ribPanelSourceRef);

            panelSrc.Items.Add(ribRow);


            //Create a Ribbon Command Button
            RibbonCommandButton ribCommandButton = new RibbonCommandButton(ribRow)
            {
                Text    = "MyTestLineButton",
                MacroID = macroLine.ElementID,
            };

            ribCommandButton.ButtonStyle = RibbonButtonStyle.LargeWithText;
            ribRow.Items.Add(ribCommandButton);
            //Create the workspace ribbon tab source reference
            WSRibbonTabSourceReference tabSrcRef = WSRibbonTabSourceReference.Create(tabSrc);

            //Get the ribbon root of the workspace
            int          curWsIndex   = cs.Workspaces.IndexOfWorkspaceName(toWorkspace);
            WSRibbonRoot wsRibbonRoot = cs.Workspaces[curWsIndex].WorkspaceRibbonRoot;

            //Set the owner of the ribbon tab source reference and add it to the workspace ribbon tab collection
            tabSrcRef.SetParent(wsRibbonRoot);
            wsRibbonRoot.WorkspaceTabs.Add(tabSrcRef);
        }