void iterateEntitiesOnLayer(const char *sName, void *pFunction(AcDbEntity *))
{
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
// Open the model space block table record.
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
const char* psSpaceName = ACDB_MODEL_SPACE;
int iIsPaper = 0;
Lpaper:
pBlkTbl->getAt(psSpaceName, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done(); pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(pEnt, AcDb::kForWrite);
if(0 == strcmp(pEnt->layer(), sName)) pFunction(pEnt);
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
if(iIsPaper == 0)
{
psSpaceName = ACDB_PAPER_SPACE;
iIsPaper = 1;
goto Lpaper;
}
}
void eraseEntity(AcDbEntity *pEnt)
{
pEnt->erase();
}
// Deletes ALL (!!!) objects on the corresponding to sName layer
void eraseEntitiesOnLayer(const char *sName)
{
iterateEntitiesOnLayer(sName, (void *(__cdecl *)(class AcDbEntity *))eraseEntity);
}
eraseEntitiesOnLayer(sLayerName); // The layer is now empty - it's safe to delete it.
AcDbLayerTable *pLayerTable;
db->getSymbolTable(pLayerTable, AcDb::kForWrite);
AcDbLayerTableRecord *pLayerTableRec;
if(Acad::eOk == pLayerTable->getAt(pEnt->layer(), pLayerTableRec, AcDb::kForWrite));// acutPrintf("\nOK!");
pLayerTableRec->erase();
pLayerTableRec->close();
pLayerTable->close();