CAD中用COM方式实现停靠式菜单
首先你必须在COM中添加引用,分别是:
AutoCAD 2006 Type Library
AutoCAD/ObjectDBX Common 16.0 Type Library
在开头需要using以下命名空间(当然其它的也是要的,这两个是菜单专用):
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
以下是代码:
[CommandMethod("myMenu")]
public static void mymenu()
{
//读取色条设定
// ctrlColorScale.ReadConfig();
//添加工具条
Autodesk.AutoCAD.Interop.AcadApplication acadApp=Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
hwTb = acadApp.MenuGroups.Item(0).Toolbars.Add("muli工具条");
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut0=hwTb.AddToolbarButton(0, "设置地形图路径", "muli工具条--设置地形图路径", "_setmappath ",null);//分别为:Index、鼠标停留时的显示信息、所调用的CommandMethod注册的命令(有下划线表示系统按钮命令,其实有无下划线效果一样),最后一个不知道是什么
FileInfo BMPtbBut0 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut0.bmp");
if(BMPtbBut0.Exists)
tbBut0.SetBitmaps(BMPtbBut0.FullName,BMPtbBut0.FullName);
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut1=hwTb.AddToolbarButton(1, "插入地形图,命令:insertMap", "muli工具条--插入地形图", "_insertMap ",null);
FileInfo BMPtbBut1 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut1.bmp");
if(BMPtbBut1.Exists)
tbBut1.SetBitmaps(BMPtbBut1.FullName,BMPtbBut1.FullName);
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut2=hwTb.AddToolbarButton(2, "查询图号", "muli工具条--查询图号", "_shoumapname ",null);
FileInfo BMPtbBut2 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut2.bmp");
if(BMPtbBut2.Exists)
tbBut2.SetBitmaps(BMPtbBut2.FullName,BMPtbBut2.FullName);
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut3=hwTb.AddToolbarButton(3, "检查容差点", "muli工具条--没添加", "_Toler ",null);
FileInfo BMPtbBut3 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut3.bmp");
if(BMPtbBut3.Exists)
tbBut3.SetBitmaps(BMPtbBut3.FullName,BMPtbBut3.FullName);
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut4=hwTb.AddToolbarButton(4, "显示后处理面板", "muli工具条--没添加", "_Palette ",null);
FileInfo BMPtbBut4 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut4.bmp");
if(BMPtbBut4.Exists)
tbBut4.SetBitmaps(BMPtbBut4.FullName,BMPtbBut4.FullName);
Autodesk.AutoCAD.Interop.AcadToolbarItem tbBut5=hwTb.AddToolbarButton(5, "显示构件查询框", "muli工具条--没添加", "_Inquire ",null);
FileInfo BMPtbBut5 = new FileInfo(@"D:\Program Files\AutoCAD 2006\Support\tbBut5.bmp");
if(BMPtbBut5.Exists)
tbBut5.SetBitmaps(BMPtbBut5.FullName,BMPtbBut5.FullName);
//添加位移放大倍数选项卡
// ctrlScaleOptions.AddTabDialog();
//添加色卡设定选项卡
// ctrlColorScale.AddTabDialog();
//添加右键菜单项
// AddContextMenu();
}
从以上代码可以看到,你的图标是可以自己设定的,而且为BMP文件。