天天看点

CAD二次开发(HelloCAD)

1.visual studio创建.NET Framework

CAD二次开发(HelloCAD)

2.新建一个项目

CAD二次开发(HelloCAD)

 3.添加引用

CAD二次开发(HelloCAD)
可以看到其中包含Autodesk.AutoCAD.Colors、Autodesk.AutoCAD.Geometry、Autodesk.AutoCAD.Runtime等等
CAD二次开发(HelloCAD)

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、直接复制过来

CAD二次开发(HelloCAD)

 6、到CAD里输入NETLOAD

CAD二次开发(HelloCAD)

然后就可以输入hello

CAD二次开发(HelloCAD)

 成功!

CAD二次开发(HelloCAD)