标签:
2015-12-17
1 //获取指定图层上所有实体ID 2 AcDbObjectIdArray GetAllEntityId(const TCHAR* layername) 3 { 4 AcDbObjectIdArray entIds; 5 bool bFilterlayer = false; 6 AcDbObjectId layerId; 7 //获取指定图层对象ID 8 if (layername != NULL) 9 { 10 AcDbLayerTable *pLayerTbl = NULL; 11 acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForRead); 12 if (!pLayerTbl->has(layername)) 13 { 14 pLayerTbl->close(); 15 return entIds; 16 } 17 pLayerTbl->getAt(layername, layerId); 18 pLayerTbl->close(); 19 bFilterlayer = true; 20 } 21 //获得块表 22 AcDbBlockTable *pBlkTbl = NULL; 23 acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlkTbl, AcDb::kForRead); 24 //块表记录 25 AcDbBlockTableRecord *pBlkTblRcd = NULL; 26 pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead); 27 pBlkTbl->close(); 28 //创建遍历器,依次访问模型空间中的每一个实体 29 AcDbBlockTableRecordIterator *it = NULL; 30 pBlkTblRcd->newIterator(it); 31 for (it->start(); !it->done(); it->step()) 32 { 33 AcDbEntity *pEnt = NULL; 34 Acad::ErrorStatus es = it->getEntity(pEnt, AcDb::kForRead); 35 if (es == Acad::eOk) 36 { 37 if (bFilterlayer)//过滤图层 38 { 39 if (pEnt->layerId() == layerId) 40 { 41 entIds.append(pEnt->objectId()); 42 } 43 } 44 else 45 { 46 // entIds.append(pEnt->objectId()); 47 pEnt->close(); 48 } 49 } 50 } 51 delete it; 52 pBlkTblRcd->close(); 53 return entIds; 54 }
标签:
原文地址:http://www.cnblogs.com/nightnine/p/5053375.html