arx炸开图纸上所有的块
static void explodeBlock1(){
AcDbObjectIdArray explodedBrefs;
AcDbVoidPtrArraybrefFragments;
AcDbDatabase* pDB = acdbCurDwg();
Acad::ErrorStatus es;
// Get the modelspace
AcDbObjectId IdModelSpace = acdbSymUtil()->blockModelSpaceId(pDB);
AcDbObjectPointer<AcDbBlockTableRecord> modelspace(IdModelSpace, AcDb::kForRead);
if (modelspace.openStatus() == Acad::eOk) {
// Now let's iterate over all entities in the modelspace
AcDbBlockTableRecordIterator* it = nullptr;
es = modelspace->newIterator(it);
if (it && (es == Acad::eOk)) {
AcDbObjectId entityId;
for (it->start(); !it->done(); it->step()) {
es = it->getEntityId(entityId);
AcDbObjectPointer<AcDbBlockReference> bref(entityId, AcDb::kForRead);
if (bref.openStatus() == Acad::eOk) {
// We found a BREF!
AcDbVoidPtrArray entitySet;
es = bref->explode(entitySet);
if (es == Acad::eOk) {
brefFragments.append(entitySet);
explodedBrefs.append(entityId);
}
// Don't append the fragments while iterating over the modelspace
}
}
delete it;
}
// Now append the new explosion fragment entities
es = modelspace->upgradeOpen(); // must be write enabled now.
for (void* p : brefFragments) {
AcDbEntity* ent = (AcDbEntity*)p;
es = modelspace->appendAcDbEntity(ent);
if (es == Acad::eOk)
ent->close();
else
delete ent; // avoid memory leak.
}
}
// Now erase the exploded BREFs
for (AcDbObjectId& brefId : explodedBrefs) {
AcDbObjectPointer<AcDbBlockReference> bref(brefId, AcDb::kForWrite);
if (bref.openStatus() == Acad::eOk)
bref->erase();
}
}
页:
[1]