vs2010+autocad2008
C#开发CAD的顺序:
1.建立类库2.添加引用:AcCui.dll,acdbmgd.dll,acmgd.dll;这三个dll在CAD的安装目录下
3.将添加的三个DLL的复制本地属性更改为False
4.将编译平台由.NET 4.0更改为.NET3.5或以下5.在项目的调试选项中,添加启动外部选项,指定CAD的启动目录(cad.exe),debug时自动启动CAD
6.设计代码(命令):键入新设计的命令调试,设计命令时,必须使用【commandmethod(“新命令”)】属性。
7.调试 在CAD中键入 NETLOAD命令,选择生成的*.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;//添加CAD基本类
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
namespace ClassLibrary1
{
public class Class1
{
[CommandMethod("HelloWorld")]//设计的新命令
public void HelloWorld()//调用HelloWorld 命令要调用的函数
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;//获取当前的活动文档
Editor acEd = acDoc.Editor;//当前的编辑器对象,命令行对象?
acEd.WriteMessage("Hello World 2017 ,LEADSOFT.ORG");//输出字符串
}
}
}
参考http://blog.csdn.net/bullzerone/article/details/73744540点击打开链接
编译运行-调试
CAD界面
输入netload 加载.dll文件
输入自定义命令helloworld
输出字符串
Hello World 2017 ,LEADSOFT.ORG