版主在吗? 我还是没实现启动CAD时自动加菜单功能,我的代码如下,麻烦你帮我看下谢谢: using System; using System.Linq; using System.Text; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using DNA; using Autodesk.AutoCAD.Colors; using Autodesk.AutoCAD.Windows; using System.Diagnostics; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Interop.Common; namespace CsMgd1 { /// <summary> /// Summary for Class1. /// </summary> public class Class1 : IExtensionApplication { public Class1() { AddMenuCom(); }
public void Initialize() { try { //cls.AddMenuCom(); } catch (System.Exception ex) { ed.WriteMessage("Error: " + ex.Message); } } public void Terminate() { } Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; [CommandMethod("Test")] public void Test() { using (Transaction trans = db.TransactionManager.StartTransaction()) { trans.Commit(); //Tools.RunCommand(false, "circle", "5,5", Tools.PauseToken, "line", "5,5", "7,5", ""); } } [CommandMethod("AM")] public static void AddMenuCom() { AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17"); AcadMenuBar menuBar = app.MenuBar; AcadMenuGroup menuGroup = app.MenuGroups.Item(0); AcadPopupMenus menus = menuGroup.Menus; AcadPopupMenu mymenu = menus.Add("MyMenu"); 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); } } }
|