C# ObjectArx AutoCAD二次開發(轉帖)

來源:互聯網
上載者:User

標籤:des   blog   http   io   ar   color   使用   sp   strong   

http://www.cnblogs.com/houlinbo/p/3325898.html

1.開發基本資料準備

用Vs2010進行Autocad 2010開發,首先下載ObjectArx 2010 SDK。

http://download.autodesk.com/akdlm/esd/dlm/objectarx/ObjectARX_2010_Win_64_and_32Bit.exe

 

2.使用Visual Studio .NET來建立一個新的類庫工程

 

(1)建立類庫項目

          啟動Visual Studio.NET,選擇”檔案>建立>工程”(File> New> Project)。在建立工程對話方塊中選擇工程類型為”Visual C#工程”,然後選擇“windows”>”類庫”模板,點擊確定按鈕來建立工程。

 

(2)添加引用

        在項目引用中添加acdbmgd.dll和acmgd.dll,預設位置在c:/ObjectARX 2010/inc-win32下。

       添加引用後,展開引用,單擊AcDbMgd和AcMgd,將其屬性複製到本地分別改為False,否則可能會出現編譯錯誤。

       AutoCAD 2010 採用 .Net Framework 3.5 版本,Vs 2010 建立預設工程採用.Net Framework 4.0 版本,必須將目標框架改為Net Framework 3.5 。修改方法:菜單 項目>ClassLibrary1屬性>應用程式>架構屬性,選擇 .Net Framework 3.5 就可以了。

 

(3) 匯入命名空間。

如:

 

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

 

(4)  加入自訂命令

建立HelloWorld的自訂AutoCAD 命令,可以這麼做:

[c-sharp] view plaincopy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using Autodesk.AutoCAD.ApplicationServices;  
  6. using Autodesk.AutoCAD.EditorInput;  
  7. using Autodesk.AutoCAD.Runtime;  
  8. namespace ClassLibrary1  
  9. {  
  10.     public class Class1  
  11.     {  
  12.         [CommandMethod("HelloWorld")]  
  13.         public void HelloWorld()  
  14.         {  
  15.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;  
  16.             ed.WriteMessage("Hello World");  
  17.         }  
  18.     }  
  19. }  

  

 

該命令在當前命令列顯示 Hello World。

 

3. 編譯和調試

(1)手動載入

點擊產生>產生解決方案,編譯完成。

要載入產生的DLL檔案,必須用Netload命令。在AutoCAD命令列輸入Netload,選擇 ClassLibrary1.dll 就可以載入了。

在命令列輸入 HelloWorld 命令,就可以看到其執行效果了。

Netload載入的程式不能卸載,要想再調試只能退出Autocad,然後重新編譯、載入。

(2)自動載入

       菜單 項目>ClassLibrary1屬性>調試>啟動操作,選擇啟動外部程式,程式名為AutoCAD.exe ,預設安裝位置在c:/Program Files/AutoCAD 2010/acad.exe;命令列參數設定  /nologo /b "d:/ClassLibrary1/ClassLibrary1/bin/debug/start.scr" 。

       start.scr 檔案是自己編寫的autocad運行指令檔,該檔案是文字檔,添加一行文本:netload "d:/ClassLibrary1/ClassLibrary1/bin/debug/ ClassLibrary1.dll" 

這樣我們就可以直接運行調試了。

(3)調試

按照以上步驟運行後,不支援斷點調試,我們還應修改acad.exe.config.xml檔案,該檔案在c:/Program Files/AutoCAD 2010/下,增加一行 <supportedRuntime version="v2.0.50727"/>內容。修改後的acad.exe.config.xml的內容如下:

 

<configuration>

   <startup>

<supportedRuntime version="v2.0.50727"/>

   </startup>

<!--All assemblies in AutoCAD are fully trusted so there‘s no point generating publisher evidence-->

   <runtime>        

<generatePublisherEvidence enabled="false"/>    

   </runtime>

</configuration>

C# ObjectArx AutoCAD二次開發(轉帖)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.