用COM方法在CAD2006中实现添加自定义菜单

前面的一个例子是用COM方法实现停靠式菜单的例子,现在是实现在CAD2006中添加菜单项,代码可能不好,老鸟不要见笑,我是和菜鸟们一起学习来着:
      首先要引用COM项的AutoCAD 2006 Type Library
核心如下:
using Autodesk.AutoCAD.Interop public static
 
Autodesk.AutoCAD.Interop.AcadPopupMenu popMenu;
[CommandMethod("myMenu")]  
  public static void mymenu()  
  {
   Autodesk.AutoCAD.Interop.AcadApplication acadApp=Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
            try
            {
                popMenu = acadApp.MenuGroups.Item(0).Menus.Add("我的菜单");
                Autodesk.AutoCAD.Interop.AcadPopupMenuItem popItem0 = popMenu.AddMenuItem(0, "设置地形图目录", "_setmappath ");
                Autodesk.AutoCAD.Interop.AcadPopupMenuItem popItem1 = popMenu.AddMenuItem(1, "查询图号", "_shoumapname ");
                Autodesk.AutoCAD.Interop.AcadPopupMenuItem popItem2 = popMenu.AddMenuItem(2, "插入地形图", "_insertMap ");
                //Autodesk.AutoCAD.Interop.AcadPopupMenuItem popItem3 = popMenu.AddMenuItem(3, "查询图号", "_sssss ");
          popMenu.InsertInMenuBar(11);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

你可能感兴趣的:(用COM方法在CAD2006中实现添加自定义菜单)