天天看點

CAD二次開發C#01

很早就裝了visual studio 2017,對比了一下LISP .net 和objectARX,綜合來說還是.net的資源多,上手快,今天心血來潮,學習一下,教程是2014CAD,我電腦是2017的

1、建立解決方案,類庫

2、引用CAD的類庫

CAD二次開發C#01

3、輸入代碼

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 cad01helloworld
{
    public class Class1
    {
        [CommandMethod("helloworld")]
        public void helloworld()
        {
            //聲明指令行對象
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //在指令行輸出一段文字
            ed.WriteMessage("你好,世界!hello world!!");
        }
    }
}
           

4、生成解決方案,調試,不知道為什麼,運作不了。但是自己另外開CAD ,加載DLL類庫,就可以運作,且運作成功。不知道原因在哪裡。輸出視窗也報一段錯誤

嚴重性    代碼    說明    項目    檔案    行    禁止顯示狀态
警告        所生成項目的處理器架構“MSIL”與引用“acmgd”的處理器架構“AMD64”不比對。這種不比對可能會導緻運作時失敗。請考慮通過配置管理器更改您的項目的目标處理器架構,以使您的項目與引用間的處理器架構保持一緻,或者為引用關聯一個與您的項目的目标處理器架構相符的處理器架構。    cad01helloworld          
           

5、運作成功截圖 

CAD二次開發C#01