ObjectARX之Mac os开发

网上关于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就会绘制一条线出来

 

 

posted @ 2019-11-05 22:07  爱学习的绿叶  阅读(958)  评论(0编辑  收藏  举报