arx 正向遍历 逆向遍历 database
void AllDb(){
AcDbBlockTable* pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead);
//获得模型空间的块表记录
AcDbBlockTableRecord* pBlkTblRcd;
pBlkTbl->getAt(ACDB采用MODEL采用SPACE, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
CString str = L"正向遍历";
//创建块表记录遍历器
AcDbBlockTableRecordIterator* pItr; //块表记录遍历器
pBlkTblRcd->newIterator(pItr);
pBlkTblRcd->close();
AcDbEntity* pEnt = NULL; //遍历的临时实体指针
for (pItr->start(); !pItr->done(); pItr->step()) {
//利用遍历器获得每一个实体
pItr->getEntity(pEnt, AcDb::kForWrite);
auto id = pEnt->id();
auto oldId = id.asOldId();
//acutPrintf();
str.AppendFormat(L"\n%d", oldId);
pEnt->close();
}
delete pItr;
AfxMessageBox(str);
}
void AllDb采用reverse()
{
AcDbBlockTable* pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead);
//获得模型空间的块表记录
AcDbBlockTableRecord* pBlkTblRcd;
pBlkTbl->getAt(ACDB采用MODEL采用SPACE, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
CString str = L"逆向遍历";
//创建块表记录遍历器
AcDbBlockTableRecordIterator* pItr; //块表记录遍历器
pBlkTblRcd->newIterator(pItr);
pBlkTblRcd->close();
AcDbEntity* pEnt = NULL; //遍历的临时实体指针
for (pItr->start(false); !pItr->done(); pItr->step(false)) {
//利用遍历器获得每一个实体
pItr->getEntity(pEnt, AcDb::kForWrite);
auto id = pEnt->id();
auto oldId = id.asOldId();
//acutPrintf();
str.AppendFormat(L"\n%d", oldId);
pEnt->close();
}
delete pItr;
AfxMessageBox(str);
}
页:
[1]