//////////////////////////////////////////////////////////////////////////////
//
// 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;
}
标签:dg,pBlkTblRcdItr,块表,sample,AcDbDatabase,test,close,include,pDb From: https://www.cnblogs.com/HRDK-CADeveloper/p/16935681.html