Exemple #1
0
        public static RibbonPanelSource AddRibbonPanelToTab(CustomizationSection cs, string tabName, string panelName)
        {
            RibbonRoot root = cs.MenuGroup.RibbonRoot;
            RibbonPanelSourceCollection panels = root.RibbonPanelSources;

            foreach (RibbonTabSource rts in root.RibbonTabSources)
            {
                if (rts.Name == tabName)
                {
                    //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 panel source reference and add it to the ribbon panel source reference collection
                    RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(rts);
                    ribPanelSourceRef.PanelId = panelSrc.ElementID;
                    rts.Items.Add(ribPanelSourceRef);

                    return(panelSrc);
                }
            }

            return(null);
        }
        /// <summary>
        /// 用于创建局部CUI文件
        /// </summary>
        /// <param name="doc">AutoCAD文档对象</param>
        /// <param name="cuiFile">CUI文件名</param>
        /// <param name="menuGroupName">菜单组的名称</param>
        /// <returns></returns>
        public static CustomizationSection AddCui(this Document doc, string cuiFile, string menuGroupName)
        {
            //声明CUI文件对象
            CustomizationSection cs;

            //如果要创建的文件不存在
            if (!File.Exists(cuiFile))
            {
                //创建CUI文件对象
                cs = new CustomizationSection
                {
                    //指定菜单组名称
                    MenuGroupName = menuGroupName
                };
                //保存CUI文件
                cs.SaveAs(cuiFile);
            }
            //如果已经存在指定的CUI文件,则打开该文件
            else
            {
                cs = new CustomizationSection(cuiFile);
            }
            //返回CUI文件对象
            return(cs);
        }
        public PopMenuTool(string arg)
        {
            localPluginVersion = arg;
            string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");

            mainCuiFile += ".cuix";
            mainCs       = new CustomizationSection(mainCuiFile);

            partialCuiFiles = new CustomizationSection[mainCs.PartialCuiFiles.Count];
            int index = 0;

            foreach (string fileName in mainCs.PartialCuiFiles)
            {
                if (File.Exists(fileName))
                {
                    partialCuiFiles[index++] = new CustomizationSection(fileName);
                }
            }
            foreach (Workspace w in mainCs.Workspaces)
            {
                if (w.ElementID.ToUpper().Equals("WS_ACADCLASSIC"))
                {
                    wsClassic = w;
                    break;
                }
            }
        }
Exemple #4
0
 public void UnloadGUI()
 {
     try
     {
         string strCuiFile            = "123";
         string mainCuiFile           = (string)Application.GetSystemVariable("MENUNAME") + ".cuix";
         CustomizationSection cs      = new CustomizationSection(mainCuiFile, true);
         CustomizationSection partCUI = null;
         bool has = false;
         foreach (string f in cs.PartialCuiFiles)
         {
             if (f.ToLower() == strCuiFile.ToLower())
             {
                 has     = true;
                 partCUI = new CustomizationSection(strCuiFile);
                 break;
             }
         }
         if (has)
         {
             cs.RemovePartialMenu(partCUI);
             cs.Save();
         }
     }
     catch (System.Exception ex)
     {
         throw new System.Exception("->UnloadGUI:" + ex.Message);
     }
 }
Exemple #5
0
        /// <summary>
        /// 装载指定的局部CUI文件
        /// </summary>
        /// <param name="cs">CUI文件</param>
        public static void LoadCui(this CustomizationSection cs)
        {
            if (cs.IsModified)
            {
                cs.Save();               //如果CUI文件被修改,则保存
            }
            //保存CMDECHO及FILEDIA系统变量
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
            object oldFileDia = Application.GetSystemVariable("FILEDIA");

            //设置CMDECHO=0,控制不在命令行上回显提示和输入信息
            Application.SetSystemVariable("CMDECHO", 0);
            //设置FILEDIA=0,禁止显示文件对话框,这样可以通过程序输入文件名
            Application.SetSystemVariable("FILEDIA", 0);
            //获取当前活动文档
            Document doc = Application.DocumentManager.MdiActiveDocument;
            //获取主CUI文件
            CustomizationSection mainCs = doc.GetMainCustomizationSection();

            //如果已存在局部CUI文件,则先卸载
            if (mainCs.PartialCuiFiles.Contains(cs.CUIFileName))
            {
                doc.SendStringToExecute("_.cuiunload " + cs.CUIFileBaseName + " ", false, false, false);
            }
            //装载CUI文件,注意文件名必须是带路径的
            doc.SendStringToExecute("_.cuiload " + cs.CUIFileName + " ", false, false, false);
            //恢复CMDECHO及FILEDIA系统变量的初始值
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
        }
Exemple #6
0
        //Default Constructor
        public CuiSamp()
        {
            // retrieve the location of, and open the ACAD Main CUI File
            string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");

            mainCuiFile += ".cui";
            cs           = new CustomizationSection(mainCuiFile);

            string entCuiFile = (string)Application.GetSystemVariable("ENTERPRISEMENU");

            if (entCuiFile.Equals("."))
            {
                entCsLoaded = false;
            }
            else
            {
                entCs       = new CustomizationSection(entCuiFile);
                entCsLoaded = true;
            }

            // Code for loading all partial CUI's listed in the main CUI file

            partials = new CustomizationSection[cs.PartialCuiFiles.Count];
            int i = 0;

            foreach (string fileName in cs.PartialCuiFiles)
            {
                if (File.Exists(fileName))
                {
                    partials[i] = new CustomizationSection(fileName);
                    i++;
                }
            }
            numPartialFiles = i;
        }
Exemple #7
0
        /// <summary>
        /// 添加菜单项所要执行的宏
        /// </summary>
        /// <param name="source">CUI文件</param>
        /// <param name="name">宏的显示名称</param>
        /// <param name="command">宏的具体命令</param>
        /// <param name="tag">宏的标识符</param>
        /// <param name="helpString">宏的状态栏提示信息</param>
        /// <param name="imagePath">宏的图标</param>
        /// <returns>返回创建的宏</returns>
        public static MenuMacro AddMacro(this CustomizationSection source, string name, string command, string tag, string helpString, string imagePath)
        {
            MenuGroup menuGroup = source.MenuGroup;//获取CUI文件中的菜单组
            //判断菜单组中是否已经定义与菜单组名相同的宏集合
            MacroGroup mg = menuGroup.FindMacroGroup(menuGroup.Name);

            if (mg == null)//如果宏集合没有定义,则创建一个与菜单组名相同的宏集合
            {
                mg = new MacroGroup(menuGroup.Name, menuGroup);
            }
            //如果已经宏已经被定义,则返回
            foreach (MenuMacro macro in mg.MenuMacros)
            {
                if (macro.ElementID == tag)
                {
                    return(null);
                }
            }
            //在宏集合中创建一个命令宏
            MenuMacro MenuMacro = new MenuMacro(mg, name, command, tag);

            //指定命令宏的说明信息,在状态栏中显示
            MenuMacro.macro.HelpString = helpString;
            //指定命令宏的大小图像的路径
            MenuMacro.macro.LargeImage = MenuMacro.macro.SmallImage = imagePath;
            return(MenuMacro);//返回命令宏
        }
Exemple #8
0
        public bool LoadFile(string path)
        {
            if (FindCuiFile(path))
            {
                CustomizationSection cus = new CustomizationSection(path, true);
                CustomizationSection c   = new CustomizationSection();
                string AcadPath          = Application.GetSystemVariable("MENUNAME").ToString() + ".cuix";
                CustomizationSection     acadCustomSection = new CustomizationSection(AcadPath);
                PartialCuiFileCollection cusparfile        = acadCustomSection.PartialCuiFiles;

                if (cusparfile.Contains(path))
                {
                    ed.WriteMessage("程序中已经包含:" + path + " 的文件,同名文件将不再次加载");
                }
                else
                {
                    this.LoadCusCUI(path);
                }
                return(true);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("False");
                return(false);
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        public void RemoveLineDoubleClick()
        {
            // 获得acad.cui文件的位置并打开它
            string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");

            mainCuiFile += ".cui";
            CustomizationSection cs = new CustomizationSection(mainCuiFile);

            // 遍历所有的双击处理动作,找到针对直线实体的处理动作
            List <DoubleClickAction> dcsToRemove = new List <DoubleClickAction>();

            foreach (DoubleClickAction dc in cs.MenuGroup.DoubleClickActions)
            {
                if (dc.DxfName.CompareTo("LINE") == 0)
                {
                    dcsToRemove.Add(dc);
                }
            }
            // 删除所有的直线实体双击处理动作
            foreach (DoubleClickAction dc in dcsToRemove)
            {
                cs.MenuGroup.DoubleClickActions.Remove(dc);
            }

            // 保存CUI文件
            if (cs.IsModified)
            {
                cs.Save();
            }
        }
Exemple #11
0
        private static void RemoveMacrosOfCommandButtons(CustomizationSection custSection, PluginCommandButton[] buttons)
        {
            string macroNames = string.Empty;

            foreach (var button in buttons)
            {
                macroNames += button.Command + "_Macro ";
            }

            int macrosToRemoveRemain = buttons.Length;

            MenuMacroCollection menuMacros = custSection.MenuGroup.MacroGroups[0].MenuMacros;

            for (int i = menuMacros.Count - 1; i >= 0; i--)
            {
                if (macroNames.Contains(menuMacros[i].macro.Name))
                {
                    menuMacros.Remove(menuMacros[i]);
                    macrosToRemoveRemain--;
                }
                if (macrosToRemoveRemain == 0)
                {
                    break;
                }
            }
            custSection.MenuGroup.MacroGroups[0].SetIsModified();
        }
Exemple #12
0
        public void editcui()
        {
            string mainCui          = Application.GetSystemVariable("MENUNAME") + ".cui";
            CustomizationSection cs = new CustomizationSection(mainCui);
            var cust = cs.CustomizationSection;

            cust.
        }
Exemple #13
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(); //否则不现实按钮
            }
        }
Exemple #14
0
        public void BuildCUI(string strMenuGroupName, string strCuiFile, System.Data.DataTable dtMacroGroup, System.Data.DataTable dtPopMenu)
        {
            try
            {
                // 为我们的局部菜单创建一个自定义区域(customization section)
                CustomizationSection pcs = new CustomizationSection();
                pcs.MenuGroupName = strMenuGroupName;

                // 添加菜单的命令组
                MacroGroup mg = new MacroGroup(dtMacroGroup.TableName, pcs.MenuGroup);
                //  pcs.MenuGroup.MacroGroups.Add(mg);
                MenuMacro mm = null;
                foreach (System.Data.DataRow r in dtMacroGroup.Rows)
                {
                    mm = mg.CreateMenuMacro(r["name"].ToString(), r["command"].ToString(), r["UID"].ToString());
                    mm.macro.HelpString = r["HelpString"].ToString();
                    // mg.AddMacro(mm);
                }
                //添加菜单项的设置
                StringCollection sc = new StringCollection();
                sc.Add("POP1");
                PopMenu pm = new PopMenu(dtPopMenu.TableName, sc, dtPopMenu.Namespace, pcs.MenuGroup);
                pcs.MenuGroup.PopMenus.Add(pm);
                PopMenuItem pmi = null;

                foreach (DataRow r in dtPopMenu.Rows)
                {
                    // 添加下拉菜单
                    if (Convert.ToBoolean(r["IsSeparator"]))
                    {
                        pmi = new PopMenuItem(pm);     //用此构造方法,即为分割条
                        pm.PopMenuItems.Add(pmi);
                    }
                    else
                    {
                        foreach (MenuMacro m in mg.MenuMacros)
                        {
                            if (m.ElementID == r["MenuMacroID"].ToString())
                            {
                                pmi = new PopMenuItem(m, r["NameRef"].ToString(), pm, -1);
                                pm.PopMenuItems.Add(pmi);
                                break;
                            }
                        }
                    }
                }
                // 最后保存文件
                pcs.SaveAs(strCuiFile);
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("->BuildMenuCUI:" + ex.Message);
            }
        }
Exemple #15
0
        public static void AddRibbonBigButtons_Method()
        {
            Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                CustomizationSection cs = new CustomizationSection((string)MgdAcApplication.GetSystemVariable("MENUNAME"));
                string curWorkspace     = (string)MgdAcApplication.GetSystemVariable("WSCURRENT");

                RibbonPanelSource panelSrc = AddRibbonPanelToTab(cs, "ANAW", "AcadNetAddinWizard2");
                MacroGroup        macGroup = cs.MenuGroup.MacroGroups[0];

                RibbonRow row = new RibbonRow();
                panelSrc.Items.Add((RibbonItem)row);

                RibbonCommandButton button1 = new RibbonCommandButton(row);
                button1.Text = "Button 1";
                MenuMacro menuMac1 = macGroup.CreateMenuMacro("Button1_Macro", "^C^CButton1_Command ", "Button1_Tag", "Button1_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button1_Label_Id");
                button1.MacroID      = menuMac1.ElementID;
                button1.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button1.KeyTip       = "Button1 Key Tip";
                button1.TooltipTitle = "Button1 Tooltip Title!";
                row.Items.Add((RibbonItem)button1);

                RibbonCommandButton button2 = new RibbonCommandButton(row);
                button2.Text = "Button 2";
                MenuMacro menuMac2 = macGroup.CreateMenuMacro("Button2_Macro", "^C^CButton2_Command ", "Button2_Tag", "Button2_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button2_Label_Id");
                button2.MacroID      = menuMac2.ElementID;
                button2.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button2.KeyTip       = "Button2 Key Tip";
                button2.TooltipTitle = "Button2 Tooltip Title!";
                row.Items.Add((RibbonItem)button2);

                RibbonCommandButton button3 = new RibbonCommandButton(row);
                button3.Text = "Button 3";
                MenuMacro menuMac3 = macGroup.CreateMenuMacro("Button3_Macro", "^C^CButton3_Command ", "Button3_Tag", "Button3_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button3_Label_Id");
                button3.MacroID      = menuMac3.ElementID;
                button3.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button3.KeyTip       = "Button3 Key Tip";
                button3.TooltipTitle = "Button3 Tooltip Title!";
                row.Items.Add((RibbonItem)button3);

                cs.Save();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(Environment.NewLine + ex.Message);
            }
        }
Exemple #16
0
        private void FillControls()
        {
            XmlDocument xmlDocument = Utils.LoadWidgetInstanceSettings(InstanceId);

            this.CbxComments.Checked      = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Comments", true);
            this.CbxContents.Checked      = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Contents", false);
            this.CbxFavorites.Checked     = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Favorites", false);
            this.CbxFriends.Checked       = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Friends", true);
            this.CbxMembership.Checked    = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Membership", true);
            this.CbxMessage.Checked       = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Message", true);
            this.CbxNotifications.Checked = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Notifications", false);
            this.CbxProperties.Checked    = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Properties", true);
            this.CbxSurvey.Checked        = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Survey", false);

            CustomizationSection customization = CustomizationSection.CachedInstance;

            if (ParentDataObject.ObjectType == 1)
            {
                DivComments.Visible      = false;
                DivContents.Visible      = false;
                DivFavorites.Visible     = false;
                DivFriends.Visible       = false;
                DivMembership.Visible    = false;
                DivMessage.Visible       = false;
                DivNotifications.Visible = false;
                DivProperties.Visible    = false;
                DivSurvey.Visible        = false;

                DivMembership.Visible = customization.Modules["Memberships"].Enabled;
                DivMessage.Visible    = customization.Modules["Messaging"].Enabled;
            }
            else
            {
                DivComments.Visible      = true;
                DivContents.Visible      = true;
                DivFavorites.Visible     = true;
                DivFriends.Visible       = true;
                DivMembership.Visible    = true;
                DivMessage.Visible       = true;
                DivNotifications.Visible = true;
                DivProperties.Visible    = true;
                DivSurvey.Visible        = true;

                DivMessage.Visible       = customization.Modules["Messaging"].Enabled;
                DivFriends.Visible       = customization.Modules["Friends"].Enabled;
                DivComments.Visible      = customization.Modules["Comments"].Enabled;
                DivNotifications.Visible = customization.Modules["Alerts"].Enabled;
                DivFavorites.Visible     = customization.Modules["Favorites"].Enabled;
                DivMembership.Visible    = customization.Modules["Memberships"].Enabled;
            }
        }
        /// <summary>
        /// 将自定义命令定义成菜单
        /// </summary>
        /// <param name="dic"></param>
        public void AddMenusToAutoCAD(List <myAutoCADNetDll> dicCmds)
        {
            string strCuiFileName       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\KFWH_CMD.cuix";
            string strGpName            = "KFWH_CMDGroup";//defined a group name
            CustomizationSection myCsec = new CustomizationSection()
            {
                MenuGroupName = strGpName
            };
            MacroGroup       mg            = new MacroGroup("KFWH_CMD", myCsec.MenuGroup);
            StringCollection scMyMenuAlias = new StringCollection();

            scMyMenuAlias.Add("KFWH_CMD_POP");
            PopMenu pmParent = new PopMenu("KFWH_CMD", scMyMenuAlias, "KFWH_CMD", myCsec.MenuGroup);

            foreach (var dll in dicCmds)//each assembly commmands
            {
                PopMenu    pmCurDll = new PopMenu(dll.DllName, new StringCollection(), "", myCsec.MenuGroup);
                PopMenuRef pmrdll   = new PopMenuRef(pmCurDll, pmParent, -1);
                foreach (var cls in dll.ListsNetClass)
                {
                    if (cls.hasCmds)
                    {
                        PopMenu    pmCurcls = new PopMenu(cls.className, new StringCollection(), "", myCsec.MenuGroup);
                        PopMenuRef pmrcls   = new PopMenuRef(pmCurcls, pmCurDll, -1);
                        foreach (var cmd in cls.ListsNetcmds)
                        {
                            MenuMacro mm = new MenuMacro(mg, cmd.MethodName, cmd.cmdName, cmd.DllName + "_" + cmd.className + "_" + cmd.cmdName, MacroType.Any);
                            //指定命令宏的说明信息,在状态栏中显示
                            if (cmd.HelpString != string.Empty)
                            {
                                mm.macro.HelpString = cmd.HelpString;
                            }
                            if (cmd.IcoName != string.Empty)
                            {
                                mm.macro.LargeImage = mm.macro.SmallImage = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\KFWH_CMD_ICON\\" + cmd.IcoName;
                            }
                            //指定命令宏的大小图像的路径
                            PopMenuItem newPmi = new PopMenuItem(mm, cmd.MethodName, pmCurcls, -1);
                            //newPmi.MacroID = cmd.DllName + "_" + cmd.className + "_" + cmd.cmdName;
                        }
                    }
                }
            }
            //myCsec.MenuGroup.AddToolbar("kfwh_cmd");
            if (myCsec.SaveAs(strCuiFileName))
            {
                this.mycuiFileName = strCuiFileName;
            }
        }
Exemple #18
0
        public static void addMenu()
        {
            string myGroupName = "myGroup";
            string myCuiName   = "myMenu.cui";
            CustomizationSection myCsection = new CustomizationSection();

            myCsection.MenuGroupName = myGroupName;

            MacroGroup mg  = new MacroGroup("myMethod", myCsection.MenuGroup);
            MenuMacro  mm1 = new MenuMacro(mg, "新建文件", "createform ", "");
            MenuMacro  mm2 = new MenuMacro(mg, "打开文件", "openfile ", "");
            MenuMacro  mm3 = new MenuMacro(mg, "打开文件", "openribbon ", "");
            //声明菜单别名
            StringCollection scMyMenuAlias = new StringCollection();

            scMyMenuAlias.Add("MyPop1");
            scMyMenuAlias.Add("MyTestPop");

            //菜单项(将显示在项部菜单栏中)
            PopMenu pmParent = new PopMenu("矿山平台", scMyMenuAlias, "我的菜单", myCsection.MenuGroup);


            //子项的菜单(多级)
            PopMenu     pm1  = new PopMenu("文件", new StringCollection(), "", myCsection.MenuGroup);
            PopMenuRef  pmr1 = new PopMenuRef(pm1, pmParent, -1);
            PopMenuItem pmi1 = new PopMenuItem(mm1, "新建", pm1, -1);
            PopMenuItem pmi2 = new PopMenuItem(mm2, "打开", pm1, -1);

            ////子项的菜单(单级)
            PopMenuItem pmi3 = new PopMenuItem(mm3, "命令", pmParent, -1);

            bool k = myCsection.SaveAs(Global.sPath + @"\" + myCuiName);

            //AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22");
            //AcadMenuBar menuBar = app.MenuBar;
            //AcadMenuGroup menuGroup = app.MenuGroups.Item(0);
            //AcadPopupMenus menus = menuGroup.Menus;
            //AcadPopupMenu mymenu = menus.Add("MyMenu");

            //mymenu.AddMenuItem(0, "Hello", "hello");
            //mymenu.AddSeparator(1);
            //mymenu.AddMenuItem(2, "Hello2", "hello");
            //AcadPopupMenu ext = mymenu.AddSubMenu(3, "Ext");
            //ext.AddMenuItem(0, "Hello", "hello");
            //ext.AddSeparator(1);
            //ext.AddMenuItem(2, "Hello2", "hello");
            //mymenu.InsertInMenuBar(menuBar.Count - 2);
        }
Exemple #19
0
        private void FillControls()
        {
            XmlDocument xmlDocument = Utils.LoadWidgetInstanceSettings(InstanceId);

            this.CbxFriends.Checked       = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Friends", true);
            this.CbxMembership.Checked    = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Membership", true);
            this.CbxMessage.Checked       = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Message", true);
            this.CbxNotifications.Checked = XmlHelper.GetElementValue(xmlDocument.DocumentElement, "Notifications", true);

            CustomizationSection customization = CustomizationSection.CachedInstance;

            DivMessage.Visible       = customization.Modules["Messaging"].Enabled;
            DivFriends.Visible       = customization.Modules["Friends"].Enabled;
            DivNotifications.Visible = customization.Modules["Alerts"].Enabled;
            DivMembership.Visible    = customization.Modules["Memberships"].Enabled;
        }
        public void SaveCui()
        {
            if (mainCs.IsModified)
            {
                mainCs.Save();
            }

            for (int i = 0; i < partialCuiFiles.Count(); i++)
            {
                CustomizationSection tempcs = partialCuiFiles[i];
                if (tempcs != null && tempcs.IsModified)
                {
                    tempcs.Save();
                }
            }
        }
Exemple #21
0
        public static void CreateRibbonTabAndPanel_Method()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                CustomizationSection cs = new CustomizationSection((string)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("MENUNAME"));
                string curWorkspace     = (string)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("WSCURRENT");

                CreateRibbonTabAndPanel(cs, curWorkspace, "MM19Tab", "MM19Panel");
                cs.Save();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(Environment.NewLine + ex.Message);
            }
        }
        private CustomizationSection GetMainCustomizationSection()
        {
            string mainMenuCuiFile;

            //17.2 is AutoCAD 2009 and its extension is CUIX
            //17.1 is AutoCAD 2008 and its extension is CUI
            if (Application.Version.Major <= 17 && Application.Version.Minor <= 1)
            {
                mainMenuCuiFile = Application.GetSystemVariable("MENUNAME") + ".cui";
            }
            else
            {
                mainMenuCuiFile = Application.GetSystemVariable("MENUNAME") + ".cuix";
            }
            var mainCui = new CustomizationSection(mainMenuCuiFile);

            return(mainCui);
        }
        //更新CUI文件
        public void UpdateCUI()
        {
            if (mainCs.IsModified)
            {
                mainCs.Save();
            }

            for (int i = 0; i < partialCuiFiles.Count(); i++)
            {
                CustomizationSection tempcs = partialCuiFiles[i];
                if (tempcs != null && tempcs.IsModified)
                {
                    tempcs.Save();
                }
            }
            string mainCuiFileName = mainCs.CUIFileName;

            Application.LoadMainMenu(mainCuiFileName);
        }
Exemple #24
0
        private void LoadMyCui(string cuiFile)
        {
            Document             doc     = Application.DocumentManager.MdiActiveDocument;
            string               mainCui = Application.GetSystemVariable("MENUNAME") + ".cuix";
            CustomizationSection cs      = new CustomizationSection(mainCui);

            PartialCuiFileCollection pcfc = cs.PartialCuiFiles;

            if (pcfc.Contains(cuiFile))
            {
                doc.Editor.WriteMessage("\nCustomization file \"" + cuiFile + "\" already loaded.");
                return;
            }


            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
            object oldFileDia = Application.GetSystemVariable("FILEDIA");

            Application.SetSystemVariable("CMDECHO", 0);
            Application.SetSystemVariable("FILEDIA", 0);

            doc.SendStringToExecute(
                "_.cuiload "
                + "\""
                + cuiFile
                + "\""
                + " ",
                false, false, false
                );
            doc.SendStringToExecute(
                "(setvar \"FILEDIA\" "
                + oldFileDia.ToString()
                + ")(princ) ",
                false, false, false
                );
            doc.SendStringToExecute(
                "(setvar \"CMDECHO\" "
                + oldCmdEcho.ToString()
                + ")(princ) ",
                false, false, false
                );
        }
Exemple #25
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);
        }
Exemple #26
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);
        }
Exemple #27
0
        public static void cuiMenu2()
        {
            //自定义的组名
            string strMyGroupName = "AgileGroup";
            //保存的CUI文件名(从CAD2010开始,后缀改为了cuix)
            string strCuiFileName = "AgileMenu.cuix";

            //创建一个自定义组(这个组中将包含我们自定义的命令、菜单、工具栏、面板等)
            CustomizationSection myCSection = new CustomizationSection();

            myCSection.MenuGroupName = strMyGroupName;

            //创建自定义命令组
            MacroGroup mg  = new MacroGroup("MyMethod", myCSection.MenuGroup);
            MenuMacro  mm1 = new MenuMacro(mg, "login", "^C^Clogin", "id_login");
            MenuMacro  mm2 = new MenuMacro(mg, "getattr", "^C^Cgetattr", "id_getattr");

            //声明菜单别名
            StringCollection scMyMenuAlias = new StringCollection();

            scMyMenuAlias.Add("POP1");
            //菜单项(将显示在项部菜单栏中)
            PopMenu pmParent = new PopMenu("Agile", scMyMenuAlias, "ID_Agile", myCSection.MenuGroup);

            //子项的菜单(多级)
            //PopMenu pm1 = new PopMenu("打开", new StringCollection(), "", myCSection.MenuGroup);
            //PopMenuRef pmr1 = new PopMenuRef(pm1, pmParent, -1);
            PopMenuItem pmi1 = new PopMenuItem(mm1, "登录", pmParent, -1);
            PopMenuItem pmi2 = new PopMenuItem(mm2, "上传", pmParent, -1);

            //子项的菜单(单级)
            //PopMenuItem pmi3 = new PopMenuItem(mm3, "保存(&S)", pmParent, -1);

            // 最后保存文件
            //myCSection.SaveAs(strCuiFileName);
            //Autodesk.AutoCAD.ApplicationServices.Application.LoadPartialMenu("");
        }
        public void Initialize()
        {
            Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                RibbonPanelSource panelSource = AutocadAPI.AddRibbonPanel("ID_ADDINSTAB", PluginName, PluginText);
                if (panelSource == null)
                {
                    editor.WriteMessage(ProgramMessage[KEY_ADDED]);
                }
                else
                {
                    RibbonSplitButton splitButton = AutocadAPI.AddSplitButtonToRibbonPanel(panelSource);

                    CustomizationSection custSection = panelSource.CustomizationSection;
                    MacroGroup           macroGroup  = custSection.MenuGroup.MacroGroups[0];

                    PluginCommandButton[] buttons = GetShowMessageButtons();
                    foreach (PluginCommandButton button in buttons)
                    {
                        AutocadAPI.AddCommandButtonToRibbonSplitButton(macroGroup, splitButton, button.Text, button.Command, button.SmallBitmapPath, button.LargeBitmapPath, button.Tooltip);
                    }

                    custSection.Save();

                    Application.ReloadAllMenus();

                    editor.WriteMessage(ProgramMessage[KEY_INST]);
                }
            }
            catch (System.Exception ex)
            {
                editor.WriteMessage(ProgramMessage[KEY_ERROR] + ex.Message);
            }
        }
Exemple #29
0
        string imagePath = ""; //15-04-2018
                               // string BaseImagePath = "";
        public SymbolLibrary(string region, string typeofSign = "", string xmlName = "", string svOptionFromLisp = "", string folderPathFromLisp = "")
        {
            InitializeComponent();
            DateTime dtmNow = DateTime.Now;

            //if (dtmNow.Day <= 31 && dtmNow.Year <= 2017 && dtmNow.Month <= 06)
            {
                try
                {
                    string mainCui = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("MENUNAME") + ".cuix";

                    CustomizationSection cs = new CustomizationSection(mainCui);

                    PartialCuiFileCollection pcfc = cs.PartialCuiFiles;

                    foreach (var _pcfc in pcfc)
                    {
                        string cuixPath = System.IO.Path.GetFileNameWithoutExtension(_pcfc);
                        if (cuixPath.Trim().ToLower().EndsWith("_au"))
                        {
                            region = "Aus";
                        }
                        else if (cuixPath.Trim().ToLower().EndsWith("_sg"))
                        {
                            region = "SG";
                        }
                        else
                        {
                            region = "NZ";
                        }
                    }
                }
                catch { }

                _typeofSign = typeofSign;
                acsc        = new AutoCompleteStringCollection();
                txtSearch.AutoCompleteCustomSource = acsc;
                txtSearch.AutoCompleteMode         = AutoCompleteMode.Suggest;
                txtSearch.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                dirPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                dirPath = dirPath.Substring(0, dirPath.LastIndexOf("\\"));
                //settingsFilePath = Path.Combine(dirPath, "Settings.ini");
                //if (System.IO.File.Exists(settingsFilePath))
                //{
                //    try
                //    {
                //        IniFile iniFile = new IniFile(settingsFilePath);
                //        BaseImagePath = iniFile.IniReadValue("setting", "ImagePath");
                //    }
                //    catch { }
                //}
                //IniFile iniFile = new IniFile(settingsFilePath);
                //signsDrawingPath =iniFile.IniReadValue("New Zealand", "Signs");

                if (String.IsNullOrWhiteSpace(_typeofSign))
                {
                    MessageBox.Show("Type not found");
                    return;
                }

                try
                {
                    //Code to read path from lisp
                    // signsDrawingPath = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GetLispSymbol("B:SYM").ToString();

                    //Autodesk.AutoCAD.Internal.Utils.GetLastCommandLines(10, true);

                    if (string.IsNullOrEmpty(folderPathFromLisp))
                    {
                        Editor       ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                        PromptResult pr = ed.GetString("Path:");

                        if (pr.Status == PromptStatus.OK)
                        {
                            path = pr.StringResult;
                        }

                        try
                        {
                            PromptResult PRSVOPtion = ed.GetString("SV");
                            if (PRSVOPtion.Status == PromptStatus.OK)
                            {
                                SVOption = PRSVOPtion.StringResult;
                            }


                            //PromptResult PRImagePath = ed.GetString("ImagePath");
                            //if (PRImagePath.Status == PromptStatus.OK)
                            //{
                            //    imagePath = PRImagePath.StringResult;
                            //    //if (BaseImagePath.Length > 0)//Add Base path if exists
                            //    //    imagePath = System.IO.Path.Combine(BaseImagePath, imagePath);
                            //}
                        }
                        catch { }
                    }
                    else
                    {
                        path     = folderPathFromLisp;
                        SVOption = svOptionFromLisp;
                    }

                    //17-05-2018
                    if (SVOption.Equals("SV-ON", StringComparison.InvariantCultureIgnoreCase))
                    {
                        SVON = true;//  chkScale.Checked = true;
                    }
                    else
                    {
                        SVON = false; chkScale.Checked = false;
                    }
                    if (!string.IsNullOrEmpty(path))
                    {
                        //Added on 24-10-2017 to remove multiple commands, if the last folder is signs then it is signs if not it is road markings
                        //string dirName = Path.GetFileName(path.TrimEnd(Path.DirectorySeparatorChar));
                        //if (dirName.Equals("Signs"))
                        //    _typeofSign = "Signs";
                        //else
                        //    _typeofSign = "RoadMarkings";

                        if (region.Equals("NZ", StringComparison.InvariantCultureIgnoreCase) || region.Equals("New Zealand", StringComparison.InvariantCultureIgnoreCase))
                        {
                            region  = "New Zealand";
                            xmlName = "B-Civil.xml";
                        }
                        else if (region.Equals("Aus", StringComparison.InvariantCultureIgnoreCase) || region.Equals("Australia", StringComparison.InvariantCultureIgnoreCase))
                        {
                            region  = "Australia";
                            xmlName = "B-Civil_AU.xml";
                        }
                        else if (region.Equals("SG", StringComparison.InvariantCultureIgnoreCase) || region.Equals("Singapore", StringComparison.InvariantCultureIgnoreCase))
                        {
                            region  = "Singapore";
                            xmlName = "B-Civil_SG.xml";
                        }

                        //foreach (string strDir in path.Split('/'))
                        //{
                        //    if (strDir.Equals("NZ", StringComparison.InvariantCultureIgnoreCase))
                        //    {
                        //        region = "New Zealand";
                        //        xmlName = "B-Civil.xml";
                        //        break;
                        //    }
                        //    else if (strDir.Equals("Aus", StringComparison.InvariantCultureIgnoreCase) || strDir.Equals("Australia", StringComparison.InvariantCultureIgnoreCase))
                        //    {
                        //        region = "Australia";
                        //        xmlName = "B-Civil_AU.xml";
                        //        break;
                        //    }
                        //    else if (strDir.Equals("SG", StringComparison.InvariantCultureIgnoreCase) || strDir.Equals("Singapore", StringComparison.InvariantCultureIgnoreCase))
                        //    {
                        //        region = "Singapore";
                        //        xmlName = "B-Civil_SG.xml";
                        //        break;
                        //    }
                        //}

                        signsDrawingPath = path;
                    }


                    if (string.IsNullOrEmpty(signsDrawingPath))
                    {
                        MessageBox.Show("Invalid drawing path");
                        abortScreenOpen = true;
                        //  Environment.Exit(-1);
                    }
                    else if (!System.IO.Directory.Exists(signsDrawingPath))
                    {
                        MessageBox.Show(signsDrawingPath + " - Path does not exist");
                        abortScreenOpen = true;
                        // Environment.Exit(-1);
                    }
                    else if (string.IsNullOrEmpty(region))
                    {
                        MessageBox.Show("Region not recognizable in the folder path");
                        abortScreenOpen = true;
                        // Environment.Exit(-1);
                    }
                    //15-04-2018
                    //if (string.IsNullOrEmpty(imagePath))
                    //    MessageBox.Show("Image path not found");
                    //else if (!System.IO.Directory.Exists(imagePath))
                    //    MessageBox.Show("Invalid Image path");

                    //30-05-2018
                    //Read the below from CUIX
                    //xmlPath = Path.Combine(dirPath, xmlName);// "NZSigns.xml");
                    //if (!System.IO.File.Exists(xmlPath))
                    //    MessageBox.Show(xmlName + " - XML file not found");
                }
                catch (Exception ex)
                {
                    signsDrawingPath = "";
                    MessageBox.Show("Invalid drawing path - " + ex.ToString());
                }

                txtRegion.Text = region;
                lblSigns.Text  = _typeofSign;
                string dirName = "";
                if (!string.IsNullOrEmpty(signsDrawingPath.Trim()))
                {
                    dirName = new DirectoryInfo(signsDrawingPath.Trim()).Name;
                }
                this.Text = dirName;//11-11-2018 "Symbol Library - " + region + " - " + _typeofSign;
            }
        }
Exemple #30
0
        public static void MenuWithIcon()
        {
            var acadCui =
                new CustomizationSection(
                    Application.GetSystemVariable("MENUNAME") + ".cuix"
                    );
            var acMenuGroup = acadCui.MenuGroup;

            // Check if the macro group exists

            var grp = default(MacroGroup);

            if (acMenuGroup.MacroGroups.Contains(cuiSectionName))
            {
                grp = acMenuGroup.FindMacroGroup(cuiSectionName);
            }
            else
            {
                grp = new MacroGroup(cuiSectionName, acMenuGroup);
            }

            var mac =
                grp.CreateMenuMacro(
                    "Table Export 2",
                    "_.TABLEEXPORT2",
                    "",
                    "Exports a table to a Unicode-compatible CSV",
                    MacroType.Edit,
                    "tableexp.bmp",
                    "tableexp.bmp",
                    ""
                    );

            // If the macros in the group, remove it
            // (otherwise we need to get it from the group for it
            // not to be added back in as duplicate when we
            // use it later... or so it seems)

            if (grp.MenuMacros.Contains(mac))
            {
                grp.MenuMacros.Remove(mac);
            }

            grp.AddMacro(mac);

            // Cycle through the PopMenus

            foreach (PopMenu menu in acadCui.MenuGroup.PopMenus)
            {
                // Ignore all except the "Edit" context menu

                if (!menu.Aliases.Contains("CMEDIT"))
                {
                    continue;
                }

                // Default position is the last in the list

                var pos = menu.PopMenuItems.Count;

                for (int i = 0; i < menu.PopMenuItems.Count; i++)
                {
                    // If we find the "Add Selected" item, then
                    // we'll insert our menu in front of that

                    var item = menu.PopMenuItems[i] as PopMenuItem;
                    if (item != null && item.MacroID == "ID_AddSelected")
                    {
                        pos = i - 1;
                        break;
                    }
                }

                // Add a separator and then the new menu item, but
                // only if it isn't already where we expect it to be

                var testPos =
                    pos < menu.PopMenuItems.Count ?
                    pos - 1 :
                    menu.PopMenuItems.Count - 1;

                var test = menu.PopMenuItems[testPos] as PopMenuItem;
                if (
                    test == null ||
                    (test != null && test.Name != "Unicode Export...")
                    )
                {
                    var sep     = new PopMenuItem(menu, pos);
                    var newItem =
                        new PopMenuItem(mac, "Unicode Export...", menu, pos + 1);

                    menu.PopMenuItems.Add(sep);
                    menu.PopMenuItems.Add(newItem);

                    // Only save and reload the CUI if we added our menu
                    // (the reload is particularly expensive)

                    acadCui.Save(true);
                    Application.ReloadAllMenus();
                }
                break;
            }
        }