C# autoCAD添加自定义菜单
public class Class1{
public Class1() { }
public static void AddMenuCom()
{
AcadApplication acadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.16.2");
acadApp.Visible = true;
AcadMenuBar menuBar = acadApp.MenuBar;
AcadMenuGroup menuGroup = acadApp.MenuGroups.Item(0);
AcadPopupMenus menus = menuGroup.Menus;
AcadPopupMenu mymenu = menus.Add("MyMenu2");
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);
//acadApp.MenuGroups.Item(0).Unload();
//AcadPopupMenu pm = acadApp.MenuGroups.Item(0).Menus.Add("建筑节能");
////声明一个AutoCAD弹出菜单项,用于获取添加的菜单项对象
//AcadPopupMenuItem pmi;
////在新建的菜单中添加一个名为"圆"的菜单项,以调用绘制圆命令
//pmi = pm.AddMenuItem(pm.Count + 1, "热评估", "hello ");
//pm.InsertInMenuBar(acadApp.MenuBar.Count + 1);
}
public static void Hello()
{
AcadApplication acadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.16.2");
acadApp.ActiveDocument.Utility.Prompt("Helloworld\n");
}
}
=========================================================================
问题:
1.我菜单添加成功了。
2.提示 没有hello命令!
3.点击菜单为什么不执行C#代码?
4.有没有其他例子参考下?
环境:VS2008+CAD2006
cacl
本帖最后由 xgr 于 2011-9-17 12:08 编辑把上句添加在using后
class是namespace,class1是含有命令的类。 新手学习!! 学习。需要传统菜单。 学习学习。 谢谢,第一次c#用cad成功呵呵
页:
[1]