一个新手的坎坷之路……
今天总算是解决了C#打开CAD并画图这个让我头疼的问题,写下来记录一下;
要实现C#直接打开CAD并画图其实也不难,首先要在项目里添加引用,不同版本的CAD添加的引用不太相同,但都大同小异,我用的是CAD2007(老年人版本哈哈),需要添加的引用是:AutoCAD 2007 Type Library 和Autodesk AutoCAD Mechanical 1.0 Type Library。在解决方案里右击项目--添加引用--在COM中选择上述2个引用。(其他版本的CAD可以在网上搜到相关引用,都差不多~)
这里需要将引用的属性更改一下,复制本地和嵌入互操作类型都改成FALSE;
命名空间写using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
然后在程序里写上Autodesk.AutoCAD.Interop.AcadApplication Cadapp; //定义一个CAD应用程序对像
Autodesk.AutoCAD.Interop.AcadDocument CadDoc; //定义一个CAD文档
AcadModelSpace CadSpace; //cad模型空间
private void button1_Click(object sender, EventArgs e)
{
AcadApplication acadApplication = new AcadA