c++ objectarx二次开发删除指定图层下所有实体
时间: 2023-12-24 12:05:34 浏览: 116
您可以使用以下代码在 AutoCAD 中删除指定图层下的所有实体:
```c++
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForRead);
AcDbLayerTableRecord *pLayerTblRcd;
AcDbObjectId layerId = AcDbObjectId::kNull;
if (pLayerTbl->getAt("LayerName", pLayerTblRcd, AcDb::kForWrite) == Acad::eOk)
{
layerId = pLayerTblRcd->objectId();
pLayerTblRcd->close();
}
pLayerTbl->close();
if (!layerId.isNull())
{
AcDbBlockTable *pBlockTbl;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTblRcd;
if (pBlockTbl->getAt(ACDB_MODEL_SPACE, pBlockTblRcd, AcDb::kForWrite) == Acad::eOk)
{
AcDbBlockTableRecordIterator *pBlkTblRcdIter;
pBlockTblRcd->newIterator(pBlkTblRcdIter);
for (; !pBlkTblRcdIter->done(); pBlkTblRcdIter->step())
{
AcDbEntity *pEnt;
if (pBlkTblRcdIter->getEntity(pEnt, AcDb::kForWrite) == Acad::eOk)
{
if (pEnt->layerId() == layerId)
{
pEnt->erase();
}
pEnt->close();
}
}
delete pBlkTblRcdIter;
pBlockTblRcd->close();
}
pBlockTbl->close();
}
```
其中,"LayerName" 部分需要替换为您要删除的图层的名称。请注意,此代码仅适用于 AutoCAD 和 ObjectARX 开发环境,不适用于其他 CAD 软件。
阅读全文