1.visual studio创建.NET Framework
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL1I2N5IGOzIzYjRzYygTMhVmMwQzNmlTNzITOhZmZ1EzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
2.新建一个项目
3.添加引用
可以看到其中包含Autodesk.AutoCAD.Colors、Autodesk.AutoCAD.Geometry、Autodesk.AutoCAD.Runtime等等
4、添加一个命令方法
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello_CAD
{
public class Class1
{
[CommandMethod("hello")]
public void Hello()
{
//声明命令行对象
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
//输出文字
editor.WriteMessage("Hello_CAD!");
}
}
}
DocumentManager包含所有document对象
5、直接复制过来
6、到CAD里输入NETLOAD
然后就可以输入hello
成功!