enum ExplodeStatus {
success = 0,
parmerr = -1,
openerr = -2,
explerr = -3,
appenderr = -4,
eraseerr = -5
};
static int ExplodeProxyInBTR(AcDbObjectId blkId, long &proxy, long &exploded);
static void ExplodeAllProxy(void)
{
AcDbObjectIdArray idsLockedLayers;
{
AcDbLayerTablePointer pTblBlk(acdbCurDwg()->layerTableId(),AcDb::kForRead);
AcDbLayerTableIterator *pIter = NULL;
if (pTblBlk->newIterator(pIter) == Acad::eOk && pIter) {
for (pIter->start(); !pIter->done(); pIter->step()) {
AcDbObjectId layId;
if (pIter->getRecordId(layId) == Acad::eOk) {
AcDbLayerTableRecordPointer pLayer(layId,AcDb::kForWrite);
if (pLayer.openStatus() == Acad::eOk) {
if (pLayer->isLocked()) {
pLayer->setIsLocked(false);
idsLockedLayers.append(layId);
}
}
}
}
delete pIter;
}
}
AcDbBlockTablePointer pTblBlk(acdbCurDwg()->blockTableId(),AcDb::kForRead);
if (pTblBlk.openStatus() == Acad::eOk) {
AcDbBlockTableIterator *pIter = NULL;
if (pTblBlk->newIterator(pIter) == Acad::eOk && pIter) {
AcDbObjectIdArray blkIds;
for (pIter->start(); !pIter->done(); pIter->step()) {
AcDbObjectId blkId;
if (pIter->getRecordId(blkId) == Acad::eOk) {
blkIds.append(blkId);
}
}
delete pIter;
pTblBlk->close();
long exploded = 0, proxy = 0;
for (int i=0; i < blkIds.length(); i++) {
if (ExplodeProxyInBTR(blkIds[i],proxy,exploded) != success) {
acutPrintf(_T("\nОшибка расчленения ACAD_PROXY_ENTITY!"));
}
}
acutPrintf(_T("\nУдалено Proxy: %d Новых объектов: %d"), proxy, exploded);
} else {
acutPrintf(_T("\nНе могу создать итератор для таблицы блоков!"));
}
} else {
acutPrintf(_T("\nНе могу открыть таблицу блоков!"));
}
{
for (int i = 0; i < idsLockedLayers.length(); i++) {
AcDbLayerTableRecordPointer pLayer(idsLockedLayers[i],AcDb::kForWrite);
if (pLayer.openStatus() == Acad::eOk) {
pLayer->setIsLocked(true);
}
}
}
}
static int ExplodeProxyInBTR(AcDbObjectId blkId, long &proxy, long &exploded)
{
Acad::ErrorStatus es = Acad::eOk;
AcDbBlockTableRecordIterator *pBlkIter = NULL;
// Массив в который добавляются расчлененные proxy
AcDbVoidPtrArray aExplProxy;
if (!blkId.isNull()) {
AcDbBlockTableRecordPointer pBtr(blkId,AcDb::kForRead);
if (pBtr.openStatus() != Acad::eOk) {
return openerr;
}
if (pBtr->newIterator(pBlkIter) != Acad::eOk || !pBlkIter) {
return openerr;
}
for (pBlkIter->start(); !pBlkIter->done(); pBlkIter->step()) {
AcDbEntity *pEnt = NULL;
if (pBlkIter->getEntity(pEnt,AcDb::kForWrite) == Acad::eOk && pEnt) {
AcDbProxyEntity *pProxy = AcDbProxyEntity::cast(pEnt);
if (pProxy && (pProxy->graphicsMetafileType() == AcDbProxyEntity::kFullGraphics ||
pProxy->graphicsMetafileType() == AcDbProxyEntity::kBoundingBox)) {
if (pProxy->graphicsMetafileType() == AcDbProxyEntity::kFullGraphics) {
pProxy->explode(aExplProxy);
proxy++;
if (pProxy->erase() != Acad::eOk) {
AcDbLine *pLine = new AcDbLine();
if (pProxy->handOverTo(pLine,false,false) == Acad::eObjectToBeDeleted) {
pLine->erase(); pLine->close();
delete pProxy;
continue;
}
}
} else {
AcDbExtents ext;
if (pProxy->getGeomExtents(ext) == Acad::eOk) {
AcGePoint3dArray arr;
arr.append(ext.minPoint());
arr.append(AcGePoint3d(ext.minPoint().x,ext.maxPoint().y,ext.minPoint().z));
arr.append(AcGePoint3d(ext.maxPoint().x,ext.maxPoint().y,ext.minPoint().z));
arr.append(AcGePoint3d(ext.maxPoint().x,ext.minPoint().y,ext.minPoint().z));
AcDb3dPolyline *pPline = new AcDb3dPolyline(AcDb::k3dSimplePoly,arr,Adesk::kTrue);
aExplProxy.append(pPline);
pPline->setLayer(pProxy->layerId());
pPline->setLinetype(pProxy->linetypeId());
pPline->setColor(pProxy->color());
}
proxy++;
if (pProxy->erase() != Acad::eOk) {
AcDbLine *pLine = new AcDbLine();
if (pProxy->handOverTo(pLine,false,false) == Acad::eObjectToBeDeleted) {
pLine->erase(); pLine->close();
delete pProxy;
continue;
}
}
}
}
pEnt->close();
}
}
exploded += aExplProxy.length();
delete pBlkIter;
AcDbObjectIdArray idsRef;
pBtr->getBlockReferenceIds(idsRef);
if (aExplProxy.length() > 0) {
es = pBtr->upgradeOpen();
if (es == Acad::eOk || es == Acad::eWasOpenForWrite) {
for (int i=0; i < aExplProxy.length(); i++) {
AcDbEntity *pEnt = static_cast<AcDbEntity *>(aExplProxy[i]);
if (pEnt) {
Acad::ErrorStatus es_curr;
es_curr = pBtr->appendAcDbEntity(pEnt);
if (es_curr != Acad::eOk) {
delete (AcDbEntity *)aExplProxy[i];
} else {
pEnt->close();
}
}
}
}
pBtr->close();
for (int i=0; i < idsRef.length(); i++) {
AcDbObjectPointer<AcDbBlockReference> pRef(idsRef[i],AcDb::kForWrite);
if (pRef.openStatus() == Acad::eOk) {
pRef->recordGraphicsModified();
}
}
}
return success;
} else {
return openerr;
}
}