- 积分
- 198
- 明经币
- 个
- 注册时间
- 2011-9-1
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
public class Class1
{
public Class1() { }
[CommandMethod("AM")]
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);
}
[CommandMethod("hello")]
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.有没有其他例子参考下?
|
|