標籤: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
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Runtime;
- namespace ClassLibrary1
- {
- public class Class1
- {
- [CommandMethod("HelloWorld")]
- public void HelloWorld()
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- ed.WriteMessage("Hello World");
- }
- }
- }
該命令在當前命令列顯示 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二次開發(轉帖)