TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- static void explodeBlock1()
- {
- AcDbObjectIdArray explodedBrefs;
- AcDbVoidPtrArray brefFragments;
- 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();
- }
- }
复制代码 |
|