//////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//////////////////////////////////////////////////////////////////////////////
//
// testdb.cpp
#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined except in internal Adesk debug builds
#endif
#include <Windows.h>
#include "rxregsvc.h"
#include "aced.h"
#include "dbsymtb.h"
#include "adslib.h"
#include "dbents.h"
#include "tchar.h"
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
void
createDwg()
{
//创建AcDbDatabase 指针
AcDbDatabase *pDb = new AcDbDatabase();
AcDbBlockTable *pBtbl;
//从pDb中获取块表指针
pDb->getSymbolTable(pBtbl, AcDb::kForRead);
AcDbBlockTableRecord *pBtblRcd;
//从pBtbl中获取当前模型控件块表记录指针
pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,
AcDb::kForWrite);
pBtbl->close();
//创建圆1 和 圆2
AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),
AcGeVector3d(0,0,1),
1.0),
*pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),
AcGeVector3d(0,0,1),
2.0);
//添加到块表记录中
pBtblRcd->appendAcDbEntity(pCir1);
//close圆1
pCir1->close();
//添加到块表记录中
pBtblRcd->appendAcDbEntity(pCir2);
//close圆1
pCir2->close();
//关闭块表记录
pBtblRcd->close();
// AcDbDatabase::saveAs() does NOT automatically
// append a DWG file extension, so it
// must be specified.
//
//
//保存database
pDb->saveAs(_T("./test1.dwg"));
//将pDb指针delete
delete pDb;
}
void readDwg()
{
// Set constructor parameter to kFalse so that the
// database will be constructed empty. This way only
// what is read in will be in the database.
//
//将第一个参数值设为kFalse,这样就会创建一个空的数据库。
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
// The AcDbDatabase::readDwgFile() function
// automatically appends a DWG extension if it is not
// specified in the filename parameter.
//
//读取数据库
if(Acad::eOk != pDb->readDwgFile(_T("./test1.dwg")))
return;
// Open the model space block table record.
//
//打开块表 只读
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
//打开模型空间块表记录 只读
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
//创建块表记录遍历器 遍历块表记录的每一个图元
AcDbBlockTableRecordIterator *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();
pBlkTblRcdItr->step())
{
//获取图元实体
pBlkTblRcdItr->getEntity(pEnt,
AcDb::kForRead);
//输出图元的类名
acutPrintf(_T("classname: %s\n"),
(pEnt->isA())->name());
//关闭图元
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
delete pDb;
}
// END CODE APPEARING IN SDK DOCUMENT.
//初始化app 注册命令
void
initApp()
{
acedRegCmds->addCommand(_T("ASDK_DWG_COMMANDS"),
_T("ASDK_CREATE"), _T("CREATE"), ACRX_CMD_MODAL, createDwg);
acedRegCmds->addCommand(_T("ASDK_DWG_COMMANDS"),
_T("ASDK_READ"), _T("READ"), ACRX_CMD_MODAL, readDwg);
}
//卸载app 注销命令
void
unloadApp()
{
acedRegCmds->removeGroup(_T("ASDK_DWG_COMMANDS"));
}
//arx的函数入口点 从此进入arxS
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
分类:
ObjectArx二次开发学习
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义