網上關於ObjectARX開發的相關介紹都基於Windows環境。Mac 環境的開發幾乎沒有,下麵介紹Mac環境下ObjectARX的開發。 AutoCAD ObjectARX開發必備條件: 1. 安裝Mac 版AutoCAD 2. 安裝AutoCAD版本對應的ObjectARX 的SDK 本文以A ...
網上關於ObjectARX開發的相關介紹都基於Windows環境。Mac 環境的開發幾乎沒有,下麵介紹Mac環境下ObjectARX的開發。
AutoCAD ObjectARX開發必備條件:
1. 安裝Mac 版AutoCAD
2. 安裝AutoCAD版本對應的ObjectARX 的SDK
本文以AutoCAD 2018 及對應的ObjectARX SDK,ObjectARX 2018 SDK 下載鏈接:http://help.autodesk.com/view/OARXMAC/2018/ENU/
ObjectARX SDK安裝成功後的路徑如下圖:
打開Xcode 新建項目時會出現Auto CAD項目信息:
新建arx項目後,xcode會自動創建一個arxmian.cpp文件。代碼如下
1 #if defined(_DEBUG) && !defined(AC_FULL_DEBUG) 2 #error _DEBUG should not be defined except in internal Adesk debug builds 3 #endif 4 5 #include <aced.h> 6 #include <rxregsvc.h> 7 8 void mycmd() 9 { 10 acutPrintf(L"My command"); 11 } 12 13 // Initialization function called from acrxEntryPoint during 14 // kInitAppMsg case. This function is used to add commands 15 // to the command stack. 16 // 17 void 18 initApp() 19 { 20 acedRegCmds->addCommand(L"MYARX_COMMANDS", L"mycmd", L"mycmd", ACRX_CMD_MODAL, mycmd); 21 } 22 23 24 // Clean up function called from acrxEntryPoint during the 25 // kUnloadAppMsg case. This function removes this app's 26 // command set from the command stack. 27 // 28 void 29 unloadApp() 30 { 31 acedRegCmds->removeGroup(L"MYARX_COMMANDS"); 32 } 33 34 35 // ARX entry point 36 // 37 extern "C" 38 AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) 39 { 40 switch (msg) { 41 case AcRx::kInitAppMsg: 42 acrxDynamicLinker->unlockApplication(appId); 43 acrxDynamicLinker->registerAppMDIAware(appId); 44 initApp(); 45 break; 46 case AcRx::kUnloadAppMsg: 47 unloadApp(); 48 break; 49 default: break; 50 } 51 return AcRx::kRetOK; 52 }
例子會註冊一個新的命令到AutoCAD中,下麵我們通過命令插入一條直線
void createLine() { AcGePoint3d startPoint(4, 2, 0); AcGePoint3d endPoint(6, 5, 0); AcDbLine* pLine = new AcDbLine(startPoint, endPoint); //獲取block 表 AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //獲取模型空間 AcDbBlockTableRecord* pModelSpace; pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite); //向模型空間添加該直線並返回其id AcDbObjectId lineId; pModelSpace->appendAcDbEntity(lineId, pLine); //關閉相關對象 pLine->close(); pModelSpace->close(); pBlockTable->close(); }
然後在mycmd函數中調用該函數:
void createLine(); void mycmd() { acutPrintf(L"Create Line"); createLine(); }
編譯項目生成bundle文件
然後我們打開AutoCAD 2018 載入該bundle文件:
在AutoCAD的命令行中輸入 mycmd就會繪製一條線出來