数据库中的层表,所有图层信息都存放在层表中
class McDbLayerTable : public McDbSymbolTable;
McDbSymbolTable.h
例如:得到所有层名
void GetAllLayerName() { // 读方式打开层表对象 McDbLayerTablePointer spLayerTabl(acdbCurDwg(),McDb::kForRead); if(spLayerTabl.openStatus() != Mcad::eOk) return; // 创建一个遍历器,准备遍历块表 McDbLayerTableIterator* pIterator = NULL; spLayerTabl->newIterator(pIterator); if(pIterator == NULL) return; // 把遍历器的指针交给智能指针管理 std::auto_ptr<McDbLayerTableIterator> spIterator(pIterator); // 遍历所有记录 for(;!pIterator->done();pIterator->step()) { McDbObjectId id; pIterator->getRecordId(id); // 读方式打开记录 McDbObjectPointer<McDbLayerTableRecord> spLayerRec(id,McDb::kForRead); if(spLayerRec.openStatus() != Mcad::eOk) continue; LPCTSTR pszName = NULL; spLayerRec->getName(pszName); CString sT; sT.Format(_T("发现层名:%s"),pszName); AfxMessageBox(sT); } };
打开所有层的代码
void CTestCommands::TestOpenAllLayer() { AcDbLayerTablePointer spLayerTable(acdbHostApplicationServices()->workingDatabase(), AcDb::kForRead); if(spLayerTable.openStatus() != Acad::eOk) return; AcDbLayerTableIterator* pLayerIter = NULL; spLayerTable->newIterator(pLayerIter); if(pLayerIter != NULL) { for(pLayerIter->start();!pLayerIter->done();pLayerIter->step()) { McDbLayerTableRecord* pRecord = NULL; pLayerIter->getRecord(pRecord,AcDb::kForWrite); if(pRecord != NULL) { pRecord->setIsOff(false); pRecord->close(); } } delete pLayerIter; } }
例如: 删除指定图层上所有实体.
void DeleteAllForLayer(McDbObjectId layerId) { // 由id得到图层名. CString sName = MrxDbgUtils::getSymbolTableRecordName(layerId); if(sName.IsEmpty()) return; // 设置过滤条件,把图层名当着过滤条件. MrxDbgRbList spFilter = Mx::mcutBuildList(8,sName,0); MrxDbgSelSet ss; // 选择指定图层上的所有实体. ss.allSelect(spFilter.data()); McDbObjectIdArray aryId; ss.asArray(aryId); // 循环删除实体。 for(int i = 0; i < aryId.length();i++) { McDbObjectPointer<McDbEntity> spEntity(aryId[i],McDb::kForWrite); if(spEntity.openStatus() != Mcad::eOk) continue; spEntity->erase(); } }