ObjectARX之Macos开发
网上关于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
8void 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//
17void
18initApp()
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//
28void
29unloadApp()
30{
31 acedRegCmds->removeGroup(L"MYARX_COMMANDS");
32}
33
34
35// ARX entry point
36//
37extern"C"
38 AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
39{
40switch (msg) {
41case AcRx::kInitAppMsg:
42 acrxDynamicLinker->unlockApplication(appId);
43 acrxDynamicLinker->registerAppMDIAware(appId);
44 initApp();
45break;
46case AcRx::kUnloadAppMsg:
47 unloadApp();
48break;
49default: break;
50 }
51return 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就会绘制一条线出来
以上是 ObjectARX之Macos开发 的全部内容, 来源链接: utcz.com/z/510462.html