Here is a sample code to explode all the entities in a selection set. Here we use the explode method of AcDbEntity class and the result of explode() is stored in a AcDbVoidPtrArray type. All the entities in AcDbVoidPtrArray are posted to a database and the original entity is erased.
static void AdskProject_EXPENT(void)
{
ads_name ss;
ads_name eName;
AcDbObjectId objId;
AcDbEntity* pEnt;
if (acedSSGet(NULL, NULL,NULL,NULL,ss) != RTNORM)
return;
long i=0;
acedSSLength(ss,&i);
//explode all enities in the selection set
for (int j=0;j<i;j++)
{
if(acedSSName(ss,j,eName) != RTNORM)
{
acedSSFree(ss);
return;
}
acdbGetObjectId(objId,eName) ;
acdbOpenAcDbEntity(pEnt,objId,AcDb::kForWrite);
AcDbVoidPtrArray eSet;
Acad::ErrorStatus es=pEnt->explode(eSet);
if (es == Acad::eOk)
{
pEnt->close();
//delete the original entity
acdbEntDel(eName);
// Add the new entities to the db
es=postToDatabase(eSet);
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to append entites to database");
acedSSFree(ss);
return;
}
}
else //self
pEnt->close();
}
acedSSFree(ss);
}
static Acad::ErrorStatus postToDatabase(AcDbVoidPtrArray eSet)
{
Acad::ErrorStatus es;
AcDbBlockTable *pBtbl;
AcDbBlockTableRecord *pBtblr;
es =acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBtbl, AcDb::kForRead);
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to open block table");
return es;
}
es=pBtbl->getAt(ACDB_MODEL_SPACE, pBtblr,AcDb::kForWrite);
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to open block table record");
es =pBtbl->close();
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to close block table");
}
return es;
}
es =pBtbl->close();
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to close block table");
return es;
}
for(int i=0; i < eSet.length(); i++)
{
AcDbObjectId ObjId;
AcDbEntity *pNewEnt=AcDbEntity::cast((AcRxObject*)eSet[i]);
es=pBtblr->appendAcDbEntity(ObjId, pNewEnt);
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to append entity");
}
es=pNewEnt->close();
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to close entity");
}
}
es=pBtblr->close();
if (es != Acad::eOk)
{
acutPrintf(L"\nFailed to close block table record");
}
return es;
}
