Esempio n. 1
0
        public void MyMenu()
        {
            //获取CAD应用程序

            AcadPopupMenus menus = app.MenuGroups.Item(0).Menus;

            foreach (AcadPopupMenu menu in menus)
            {
                if (menu.Name == "我的Com菜单")
                {
                    menu.InsertInMenuBar(app.MenuBar.Count + 1);
                    return;
                }
            }

            AcadPopupMenu pmParnet = menus.Add("我的Com菜单");  //添加根菜单


            //多级
            AcadPopupMenu     pm   = pmParnet.AddSubMenu(pmParnet.Count + 1, "一级菜单");
            AcadPopupMenuItem pmi0 = pm.AddMenuItem(pm.Count + 1, "打开窗口  ", "OpenWindow\n");  //第一个参数是在菜单项中的位置(第几项),第二个参数是显示的名称,第三个参数是点击之后执行的命令
            AcadPopupMenuItem pmi1 = pm.AddMenuItem(pm.Count + 1, "输出实体 ", "ListEntities\n");

            //单级

            AcadPopupMenuItem pmi2 = pmParnet.AddMenuItem(pmParnet.Count + 1, "退出", "EXIT\n");
            AcadPopupMenuItem pmi3 = pmParnet.AddMenuItem(pmParnet.Count + 1, "删除我的菜单", "DeleteMenu\n");

            //将创建的菜单加入到CAD的菜单中
            pmParnet.InsertInMenuBar(app.MenuBar.Count + 1);
        }
Esempio n. 2
0
        //加载菜单栏
        public void AddMenu()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            doc.Editor.WriteMessage("添加菜单栏成功!>>>>>>>>>>>>>>");
            AcadApplication acadApp = Application.AcadApplication as AcadApplication;

            //创建建菜单栏的对象
            AcadPopupMenu myMenu = null;

            // 创建菜单
            if (myMenu == null)
            {
                // 菜单名称
                myMenu = acadApp.MenuGroups.Item(0).Menus.Add("实用工具箱");

                myMenu.AddMenuItem(myMenu.Count, "批量重命名PDF", "THTM ");
                myMenu.AddMenuItem(myMenu.Count, "测试程序", "CSCS ");
                myMenu.AddMenuItem(myMenu.Count, "标高及桩号初始化", "GLCSH ");
                myMenu.AddMenuItem(myMenu.Count, "两行数值相减", "SZXJ ");
                myMenu.AddMenuItem(myMenu.Count, "生成节点桩号", "JDZH ");
                myMenu.AddMenuItem(myMenu.Count, "拾取线生成标高", "QXBG ");
                myMenu.AddMenuItem(myMenu.Count, "选点生成桩号及标高", "QDZHBG ");

                myMenu.AddSeparator(myMenu.Count); //加入分割符号

                //开始加子菜单栏
                AcadPopupMenu subMenu = myMenu.AddSubMenu(myMenu.Count, "图号重排");  //子菜单对象
                subMenu.AddMenuItem(myMenu.Count, "按行重排", "THCP R ");
                subMenu.AddMenuItem(myMenu.Count, "按列重排", "THCP C ");

                //结束加子菜单栏
            }

            // 菜单是否显示  看看已经显示的菜单栏里面有没有这一栏
            bool isShowed = false;                          //初始化没有显示

            foreach (AcadPopupMenu menu in acadApp.MenuBar) //遍历现有所有菜单栏
            {
                if (menu == myMenu)
                {
                    isShowed = true;
                    break;
                }
            }

            // 显示菜单 加载自定义的菜单栏
            if (!isShowed)
            {
                myMenu.InsertInMenuBar(acadApp.MenuBar.Count);
            }
        }
Esempio n. 3
0
        /// <summary> 添加菜单的操作可以直接在AutoCAD运行过程中执行,而不用像Revit中一样必须要先关闭然后在程序启动时添加 </summary>
        public static void AddMenuItem()
        {
            // This example creates a new menu called TestMenu and inserts a menu item
            // into it. The menu is then displayed on the menu bar.
            // To remove the menu after execution of this macro, use the Customize Menu
            // option from the Tools menu.

            var app = Application.AcadApplication as AcadApplication;

            // AcadMenuGroup 表示AutoCAD中加载的一个.cuix文件中的菜单集合。
            // MenuGroups.Item(0) 与 Menubar 中的菜单集合 并不是同一个集合,它的 MenuFileName 属性对应的文件为:
            // C:\Users\zengfy\appdata\roaming\autodesk\autocad 2014\r19.1\chs\support\acad.cuix
            AcadMenuGroup currMenuGroup = app.MenuGroups.Item(0);

            //Create the new menu
            AcadPopupMenu topPpMenu = currMenuGroup.Menus.Add("MenuHandler");

            // Assign the macro string the VB equivalent of "ESC ESC _open "
            string openMacro = "ESC ESC _open "; // VBA 中的写法:openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)

            //Add a menu item to the new menu, Macro 即对应要在命令行中输入的字符
            AcadPopupMenuItem childMenuItem = topPpMenu.AddMenuItem(Index: topPpMenu.Count + 1, Label: "Open",
                                                                    Macro: openMacro);

            // 添加可以包含子项的菜单
            AcadPopupMenu     menuItemContainer = topPpMenu.AddSubMenu(Index: topPpMenu.Count + 1, Label: "block");
            AcadPopupMenuItem childMenuItem2    = menuItemContainer.AddMenuItem(Index: menuItemContainer.Count + 1,
                                                                                Label: "画圆", Macro: "Circle ");

            // Display the menu on the menu bar

            // If index is a string, the name of the popup menu must contain any underscore that appears in the menu.
            topPpMenu.InsertInMenuBar(Index: "工具(&T)");  // Index: app.MenuBar.Count + 1
            return;

            // 以下为功能测试项 --------------------------------------------------------

            // The index must be either an integer or a string. If an integer, the index must be between 0 and N-1, where N is the number of objects in the menu bar. The new item will be added immediately before the specified index location.
            topPpMenu.InsertInMenuBar(Index: app.MenuBar.Count + 1);

            // 从 MenuBar 提取一个菜单项。
            // 注意:MenuBar 只能用来读取其中的 AcadPopupMenu 集合,而不能操纵菜单项的添加或移除。
            AcadMenuBar mb = app.MenuBar;
            // 下面这个Item(0)对应的是AutoCAD界面中菜单栏中的第一个菜单项,通常这个菜单项为“文件(F)”
            AcadPopupMenu ppm1 = mb.Item(0);

            // 将菜单项从 MenuBar 中移除
            topPpMenu.RemoveFromMenuBar();
        }
Esempio n. 4
0
        public void AddMenu()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            AcadApplication acadApp = Application.AcadApplication as AcadApplication;

            //创建建菜单栏的对象
            AcadPopupMenu myMenu = null;

            // 创建菜单
            if (myMenu == null)
            {
                // 菜单名称
                myMenu = acadApp.MenuGroups.Item(0).Menus.Add("BF Custom Tools");

                myMenu.AddMenuItem(myMenu.Count, "改比例", "GBL "); //每个命令后面有一个空格,相当于咱们输入命令按空格
                myMenu.AddMenuItem(myMenu.Count, "自动归层", "ZDGC ");
                myMenu.AddMenuItem(myMenu.Count, "绘图环境", "HTHJ ");
                //开始加子菜单栏
                AcadPopupMenu subMenu = myMenu.AddSubMenu(myMenu.Count, "BlockTools");  //子菜单对象
                subMenu.AddMenuItem(myMenu.Count, "插入灯具", "CDJ ");
                subMenu.AddMenuItem(myMenu.Count, "插入图框", "TK ");
                subMenu.AddMenuItem(myMenu.Count, "插入铝材", "LXC ");
                myMenu.AddSeparator(myMenu.Count); //加入分割符号
                //结束加子菜单栏
            }

            // 菜单是否显示  看看已经显示的菜单栏里面有没有这一栏
            bool isShowed = false;                          //初始化没有显示

            foreach (AcadPopupMenu menu in acadApp.MenuBar) //遍历现有所有菜单栏
            {
                if (menu == myMenu)
                {
                    isShowed = true;
                    break;
                }
            }

            // 显示菜单 加载自定义的菜单栏
            if (!isShowed)
            {
                myMenu.InsertInMenuBar(acadApp.MenuBar.Count);
            }

            doc.Editor.WriteMessage("\n添加菜单栏成功!………………………………………………");
        }
        //加载菜单栏
        public void AddMenu()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            doc.Editor.WriteMessage("添加菜单栏成功!>>>>>>>>>>>>>>");
            AcadApplication acadApp = Application.AcadApplication as AcadApplication;

            //创建建菜单栏的对象
            AcadPopupMenu myMenu = null;

            // 创建菜单
            if (myMenu == null)
            {
                // 菜单名称
                myMenu = acadApp.MenuGroups.Item(0).Menus.Add("个人专用菜单工具(2020.07)");

                myMenu.AddMenuItem(myMenu.Count, "文字批量替换", "TBR "); //每个命令后面有一个空格,相当于咱们输入命令按空格
                myMenu.AddMenuItem(myMenu.Count, "文字批量对齐", "TBA ");
                myMenu.AddMenuItem(myMenu.Count, "输出文本", "CTE ");
                //开始加子菜单栏
                AcadPopupMenu subMenu = myMenu.AddSubMenu(myMenu.Count, "CADLinkToEXcel");  //子菜单对象
                subMenu.AddMenuItem(myMenu.Count, "Excel表格导入", "CTES ");
                subMenu.AddMenuItem(myMenu.Count, "由Excel数据更新CAD表格数据", "UCTFE ");
                subMenu.AddMenuItem(myMenu.Count, "由CAD表格数据更新Excel表格数据", "UEFCT ");
                myMenu.AddSeparator(myMenu.Count); //加入分割符号
                //结束加子菜单栏
            }

            // 菜单是否显示  看看已经显示的菜单栏里面有没有这一栏
            bool isShowed = false;                          //初始化没有显示

            foreach (AcadPopupMenu menu in acadApp.MenuBar) //遍历现有所有菜单栏
            {
                if (menu == myMenu)
                {
                    isShowed = true;
                    break;
                }
            }

            // 显示菜单 加载自定义的菜单栏
            if (!isShowed)
            {
                myMenu.InsertInMenuBar(acadApp.MenuBar.Count);
            }
        }
Esempio n. 6
0
        private void Dfs(XmlNodeList nodes, AcadPopupMenu parentMenu)
        {
            var position = 1;

            foreach (XmlNode node in nodes)
            {
                position++;
                var typeAttribute = node.Attributes["type"];
                if (typeAttribute == null)
                {
                    MessageBox.Show("MenuItemType was null", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
                MenuItemType type;
                var          availableType = MenuItemType.TryParse(typeAttribute.Value, out type);
                if (!availableType)
                {
                    MessageBox.Show("Unrecognized menu item type", "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
                switch (type)
                {
                case MenuItemType.MenuItem:
                    var label = node.Attributes["label"].Value;
                    var macro = node.Attributes["macro"].Value;
                    parentMenu.AddMenuItem(position, label, macro);
                    break;

                case MenuItemType.Separator:
                    parentMenu.AddSeparator(position);
                    break;

                case MenuItemType.SubMenu:
                    label = node.Attributes["label"].Value;
                    var menu = parentMenu.AddSubMenu(position, label);
                    Dfs(node.ChildNodes, menu);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 添加测试菜单
        /// </summary>
        /// <param name="mainMenu"></param>
        private static void AddTestMenu(AcadPopupMenu mainMenu)
        {
            AcadPopupMenuItem popMenuItemTest;
            //在新建的菜单中添加一个一级菜单
            AcadPopupMenu popMenuTest = mainMenu.AddSubMenu(mainMenu.Count + 1, "测试功能 ");

            //添加子菜单
            popMenuItemTest            = popMenuTest.AddMenuItem(popMenuTest.Count + 1, "欢迎", "HelloWorld ");
            popMenuItemTest.HelpString = "欢迎";            //状态栏提示信息
            popMenuTest.AddSeparator(popMenuTest.Count + 1);

            //添加子菜单
            popMenuItemTest            = popMenuTest.AddMenuItem(popMenuTest.Count + 1, "图层信息", "GetLayerPro ");
            popMenuItemTest.HelpString = "图层信息";            //状态栏提示信息
            popMenuTest.AddSeparator(popMenuTest.Count + 1);

            //添加一个分隔条以区分不同类型的命令
            mainMenu.AddSeparator(mainMenu.Count + 1);
        }
Esempio n. 8
0
        /// <summary>
        /// 添加字体自动替换的菜单
        /// </summary>
        /// <param name="mainMenu"></param>
        private static void AddFontChangerMenu(AcadPopupMenu mainMenu)
        {
            //声明一个AutoCAD弹出菜单项,用于获取添加的菜单项对象
            AcadPopupMenuItem popMenuItemFont;
            //在新建的菜单中添加一个一级菜单
            AcadPopupMenu popMenuFont = mainMenu.AddSubMenu(mainMenu.Count + 1, "字体替换 ");

            //添加子菜单
            popMenuItemFont            = popMenuFont.AddMenuItem(popMenuFont.Count + 1, "开启", "StartFontChange ");
            popMenuItemFont.HelpString = "开启字体自动替换";            //状态栏提示信息
            popMenuFont.AddSeparator(popMenuFont.Count + 1);

            //添加子菜单
            popMenuItemFont            = popMenuFont.AddMenuItem(popMenuFont.Count + 1, "关闭", "StopFontChange ");
            popMenuItemFont.HelpString = "关闭字体自动替换";            //状态栏提示信息
            popMenuFont.AddSeparator(popMenuFont.Count + 1);

            //添加一个分隔条以区分不同类型的命令
            mainMenu.AddSeparator(mainMenu.Count + 1);
        }
Esempio n. 9
0
        /// <summary>
        /// 添加桩基信息的菜单
        /// </summary>
        /// <param name="mainMenu"></param>
        private static void AddPileFoundationMenu(AcadPopupMenu mainMenu)
        {
            AcadPopupMenuItem popMenuItemPileFoundation;
            //在新建的菜单中添加一个一级菜单 桩基
            AcadPopupMenu popMenuPileFoundation = mainMenu.AddSubMenu(mainMenu.Count + 1, "桩基功能 ");

            //添加子菜单
            popMenuItemPileFoundation            = popMenuPileFoundation.AddMenuItem(popMenuPileFoundation.Count + 1, "桩信息", "GetPileInfo ");
            popMenuItemPileFoundation.HelpString = "读取桩的基本信息";            //状态栏提示信息
            popMenuPileFoundation.AddSeparator(popMenuPileFoundation.Count + 1);

            //添加子菜单
            popMenuItemPileFoundation            = popMenuPileFoundation.AddMenuItem(popMenuPileFoundation.Count + 1, "桩位置", "GetPileCoordinate ");
            popMenuItemPileFoundation.HelpString = "选取区域,读取桩的坐标";            //状态栏提示信息
            popMenuPileFoundation.AddSeparator(popMenuPileFoundation.Count + 1);


            //添加一个分隔条以区分不同类型的命令
            mainMenu.AddSeparator(mainMenu.Count + 1);
        }
Esempio n. 10
0
        public void AddMenu()
        {
            //COM方式获取AutoCAD应用程序对象
            AcadApplication acadApp = (AcadApplication)Application.AcadApplication;
            //为AutoCAD添加一个新的菜单,并设置标题为"我的菜单"
            AcadPopupMenu pm = acadApp.MenuGroups.Item(0).Menus.Add("我的菜单");
            //声明一个AutoCAD弹出菜单项,用于获取添加的菜单项对象
            AcadPopupMenuItem pmi;

            //在新建的菜单中添加一个名为"圆"的菜单项,以调用绘制圆命令
            pmi = pm.AddMenuItem(pm.Count + 1, "圆", "_Circle ");
            //设置状态栏提示信息
            pmi.HelpString = "用指定半径创建圆";
            //添加名为"直线"的菜单项,以调用绘制直线命令
            pmi            = pm.AddMenuItem(pm.Count + 1, "直线", "_Line ");
            pmi.HelpString = "创建直线段";
            //添加名为"多段线"的菜单项,以调用绘制多段线命令
            pmi            = pm.AddMenuItem(pm.Count + 1, "多段线", "_Polyline ");
            pmi.HelpString = "创建二维多段线";
            //添加名为"矩形"的菜单项,以调用绘制矩形多段线命令
            pmi            = pm.AddMenuItem(pm.Count + 1, "矩形", "_Rectangle ");
            pmi.HelpString = "创建矩形多段线";
            //添加一个分隔条以区分不同类型的命令
            pm.AddSeparator(pm.Count + 1);
            //添加一个名为"修改"的子菜单
            AcadPopupMenu menuModify = pm.AddSubMenu(pm.Count + 1, "修改");

            //在"修改"子菜单下添加用于复制、删除、移动及旋转操作的菜单项,并设置相应的状态栏提示信息
            pmi            = menuModify.AddMenuItem(menuModify.Count + 1, "复制", "_Copy ");
            pmi.HelpString = "复制对象";
            pmi            = menuModify.AddMenuItem(menuModify.Count + 1, "删除", "_Erase ");
            pmi.HelpString = "从图形删除对象";
            pmi            = menuModify.AddMenuItem(menuModify.Count + 1, "移动", "_Move ");
            pmi.HelpString = "移动对象";
            pmi            = menuModify.AddMenuItem(menuModify.Count + 1, "旋转", "_Rotate ");
            pmi.HelpString = "绕基点旋转对象";
            //将定义的菜单显示在AutoCAD菜单栏的最后
            pm.InsertInMenuBar(acadApp.MenuBar.Count + 1);
        }
Esempio n. 11
0
        public static void AddCmdtoMenuBar(List <gcadDllcmd> cmds)
        {
            var           dllName = Assembly.GetExecutingAssembly().ManifestModule.Name.Substring(0, Assembly.GetExecutingAssembly().ManifestModule.Name.Length - 4);
            var           gcadApp = Application.AcadApplication as AcadApplication;
            AcadMenuGroup mg      = null;

            for (int i = 0; i < gcadApp.MenuGroups.Count; i++)
            {
                if (gcadApp.MenuGroups.Item(i).Name == "ACAD")
                {
                    mg = gcadApp.MenuGroups.Item(i);
                }
            }

            for (int i = 0; i < mg.Menus.Count; i++)
            {
                if (mg.Menus.Item(i).Name == dllName)
                {
                    mg.Menus.Item(i).RemoveFromMenuBar();
                }
            }
            AcadPopupMenu popMenu = mg.Menus.Add(dllName);

            for (int i = 0; i < cmds.Count; i++)
            {
                var dllPopMenu = popMenu.AddSubMenu(popMenu.Count + 1, cmds[i].DllName);
                for (int j = 0; j < cmds[i].clsCmds.Count; j++)
                {
                    var clsPopMenu = dllPopMenu.AddSubMenu(dllPopMenu.Count + 1, cmds[i].clsCmds[j].clsName);
                    for (int k = 0; k < cmds[i].clsCmds[j].curClscmds.Count; k++)
                    {
                        var methodPopMenu = clsPopMenu.AddMenuItem(clsPopMenu.Count + 1, cmds[i].clsCmds[j].curClscmds[k].cmdName, cmds[i].clsCmds[j].curClscmds[k].cmdMacro + " ");
                    }
                }
            }
            popMenu.InsertInMenuBar(mg.Menus.Count + 1);
        }