建立CAD -- NET托管程序比较容易实现, / using System ; using Autodesk.AutoCAD.Runtime ; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Interop; using System.Runtime.InteropServices;//系统com支持 using Autodesk.AutoCAD.EditorInput; [assembly: CommandClass(typeof(ClassLibrary.SLClass))] namespace ClassLibrary { /// <summary> /// Summary description for SLClass. /// </summary> public class SLClass { public SLClass() { // // TODO: Add constructor logic here // } public void Initialize() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("SLTireCAD系统初始化中……"); } // Define Command "AsdkCmd1" [CommandMethod("InitMenuTool")] static public void LoginSLTireCAD() // This method can have any name { // Put your command code here AcadApplication AcadApp; try { AcadApp = (AcadApplication) Marshal.GetActiveObject("AutoCAD.Application"); } catch { AcadApp = null; } if (AcadApp!=null) { AcadPopupMenu Mymenu=AcadApp.MenuGroups.Item(0).Menus.Add("XXXXCAD"); Mymenu.AddMenuItem(0,"系统登陆","_LoginXXXCAD "); Mymenu.AddMenuItem(1,"圆","_circle "); Mymenu.AddSeparator(2); AcadPopupMenu subm=Mymenu.AddSubMenu("","子菜单");//下级菜单 subm.AddMenuItem(0,"射线","Xline "); Mymenu.AddSeparator(4); Mymenu.AddMenuItem(5,"圆弧","_ARC "); Mymenu.AddMenuItem(6,"关于SLTireCAD","__AbouteSLCAD"); Mymenu.InsertInMenuBar(14);//插入到当前菜单组14 AcadToolbar MyToolBar=AcadApp.MenuGroups.Item(0).Toolbars.Add("SLTireCAD工具栏"); AcadToolbarItem tbBut1 = MyToolBar.AddToolbarButton(0, "系统登陆", "系统登陆", "_LoginXXCAD\n", false); //tbBut1.SetBitmaps("D:\\BMP_BTN_LOGIN.bmp","D:\\BMP_BTN_LOGIN.bmp"); AcadToolbarItem tbBut2 = MyToolBar.AddToolbarButton(2, "关于SLTireCAD", "关于XXCAD", "_AbouteXXCAD\n", false); //tbBut2.SetBitmaps("BMP_BTN_LOGIN.bmp","BMP_BTN_LOGIN.bmp"); tbBut2.TagString ="关于SLTireCAD……";
//tbBut.SetBitmaps("first.bmp", "first.bmp"); MyToolBar.top = 100; MyToolBar.left =100; MyToolBar.Visible = true; } } } } |