|
发表于 2014-9-26 09:44:23
|
显示全部楼层
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using cadApp = Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Interop; //引用com类库[assembly: ExtensionApplication(typeof(yfCAD.myClass))] //启动时加载工具栏,注意typeof括号里的类库名 namespace yfCAD{ public class myClass : Autodesk.AutoCAD.Runtime.IExtensionApplication //注意:重要 { public void Initialize() { AddToolBar();//启时自动加载工具栏 } // 清除操作,不可缺少 public void Terminate() { } //加载工具栏 public void AddToolBar() { string path = Path(); Autodesk.AutoCAD.Interop.AcadApplication acadApp = (AcadApplication) Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication; Autodesk.AutoCAD.Interop.AcadToolbar atb = null; Autodesk.AutoCAD.Interop.AcadToolbarItem atbi = null; try { atb = acadApp.MenuGroups.Item("ACAD").Toolbars.Add("您自己工具栏的名称"); //示例atbi = atb.AddToolbarButton(0, "工具栏名称", "帮助", "命令 ", false); //命令后,紧跟一空格,否则处于等待状态 atbi = atb.AddToolbarButton(0, "数字文本求和", "数字文本求和", "Sum ", false); //示例atbi.SetBitmaps(工具栏图片文件路径,工具栏图片文件路径); atbi.SetBitmaps(acadApp.Path.Trim() + "\\***.bmp", acadApp.Path.Trim() + "\\***.bmp"); atbi = atb.AddToolbarButton(1, "批量转换", "批量转换", "dwgToPdf ", false); atbi.SetBitmaps(acadApp.Path.Trim() + "\\***.bmp", acadApp.Path.Trim() + "\\***.bmp"); //工具栏靠右边停靠 atb.Dock(Autodesk.AutoCAD.Interop.Common.AcToolbarDockStatus.acToolbarDockRight); atb.Visible = true; } catch { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("加载工具栏出错……"); } }
网上代码,希望有用,地址:http://bbs.mjtd.com/thread-81755-1-1.html
楼主可以看下 |
|