[CommandMethod("caidan")]
public void ShowJingDianMenu()
{
try
{
IAcadApplication app = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as AcadApplication;
if (app == null) return;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
if (app.MenuGroups == null || app.MenuGroups.Item(0) == null) return;
AcadMenuGroups acadMenuGroups = app.MenuGroups;
int index = 0;
foreach (AcadMenuGroup item in acadMenuGroups)
{
string name = item.Name;
//name.ToLower() == "3dtool_menugroup"
if ( name.ToLower() == "amacad")
break;
index++;
}
for (int i = 0; i < app.MenuGroups.Item(index).Menus.Count; i++)
{
if (app.MenuGroups.Item(index).Menus.Item(i).Name == "3DTool")
{
//app.MenuGroups.Item(index).Menus.Item(i).RemoveFromMenuBar();
ed.WriteMessage("3DTool已存在菜单组!");
return;
}
}
//添加根菜单
AcadPopupMenu pmParnet = app.MenuGroups.Item(index).Menus.Add("3DTool");
int countmenubar = app.MenuBar.Count;
//多级 AcadPopupMenu
//AcadPopupMenu pm = pmParnet.AddSubMenu(pmParnet.Count + 1, "绘制模型");
//AcadPopupMenuItem pmi0 = pm.AddMenuItem(pm.Count + 1, "文件 ", "OPEN1\n"); //第一个参数是在菜单项中的位置(第几项),第二个参数是显示的名称,第三个参数是点击之后执行的命令
//AcadPopupMenuItem pmi1 = pm.AddMenuItem(pm.Count + 1, "模版 ", "OPEN2\n");
//单级 AcadPopupMenuItem
pmParnet.AddMenuItem(pmParnet.Count + 1, "绘制模型", "_CON ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "导出设备清单", "_ETOE ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "修改模型", "_MDC ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "修改编号", "_GAT ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "输出GA图", "_GAT ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "导出BOM清单", "_EBOM ");
pmParnet.AddSeparator(pmParnet.Count + 1);
pmParnet.AddMenuItem(pmParnet.Count + 1, "镜像和改属性", "cusmirror ");
//将创建的菜单加入到CAD的菜单中
pmParnet.InsertInMenuBar(countmenubar + 1);
ed.WriteMessage("3DTool工具条生成完成!");
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
com 接口添加菜单栏
标签:Count,pmParnet,C#,MenuGroups,app,下拉子,菜单栏,Item,AddMenuItem From: https://blog.51cto.com/u_15825922/7022037