基于C#进行AutoCAD二次开发初探(二)——C#编写代码直接打开AutoCAD并显示图形
AutoCAD 2006 Type Library //我用的是CAD2006版
AutoCAD/ObiectDBX Common 16.0 Type Library
把这两个引用的命名空间引进来
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
//就可以写代码了
AcadApplication CadApp; //定义一个CAD应用程序对像
AcadDocument CadDoc; //定义一个CAD文档
AcadModelSpace CadSpace; //这是CAD的模型空间
//然后就先一个CAD应用程序
CadApp = new AcadApplication();
CadApp.Visible = true; //如果你想把CAD显示到前台来,就设为true
CadDoc = CadApp.ActiveDocument; //获取CAD当前活动的文档
CadSpace = (AcadModelSpace)CadDoc.ModelSpace; //获得命名空间
double[] c = new double[6]; //我随便定义一个要画线的点数组,记得点这个数组里是按XYZ坐标顺序存放的噢
c[0] = 34; c[1] = 98; c[2] = 67; c[3] = 956; c[4] = 655; c[5] = 322; //随便输的
CadSpace.Add3DPoly(c); //我这里画的是三维多段线,你要画其它的线型的话,到找一下对应的方法即可。
以上代码转载自https://bbs.csdn.net/topics/390306941?page=1,四楼回答者。