static void ADSKMyGroupWTEST()
{
Acad::ErrorStatus es;
TCHAR fullpath[_MAX_PATH];
int ret = acedFindFile(_T("C:\\VESSELBLOCKS.dwg"),
fullpath );
if ( ret != RTNORM )
return;
AcDbDatabase *pSrcDb = new AcDbDatabase( false, false );
es = pSrcDb->readDwgFile( fullpath, _SH_DENYNO );
if ( es != Acad::eOk )
{
acutPrintf( _T("\nCan not open file.") );
delete pSrcDb;
return;
}
AcApDocument *pActiveDoc
= acDocManager->mdiActiveDocument();
AcDbDatabase *pDestDb
= pActiveDoc->database();
AcDbObjectIdArray objIds2Copy;
AcDbBlockTable *pBlockTable,*pBlockTable2;
es = pSrcDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbObjectId recordId = AcDbObjectId::kNull;
es = pBlockTable->getAt(ACRX_T("CP_STERN_SY"), recordId, AcDb::kForRead);
objIds2Copy.append(recordId);
es = pBlockTable->close();
AcDbIdMapping idMap;
es = pSrcDb->wblockCloneObjects(objIds2Copy,
acdbSymUtil()->blockModelSpaceId(pDestDb),
idMap, AcDb::kDrcReplace);
if(es == Acad::eOk)
{
acutPrintf( _T("\nCloned the block to the current drawing.") );
AcDbObjectId targetBlockId = AcDbObjectId::kNull;
es = pDestDb->getSymbolTable(pBlockTable2, AcDb::kForRead);
es = pBlockTable2->getAt(ACRX_T("CP_STERN_SY"),
targetBlockId,
AcDb::kForRead);
SetBlockDrawOrder(recordId,targetBlockId,idMap);
es = pBlockTable2->close();
}
else
acutPrintf( _T("\nFailed to clone the block to the current drawing.") );
delete pSrcDb;
}
static void SetBlockDrawOrder(AcDbObjectId srcBlockId,
AcDbObjectId targetBlockId,
AcDbIdMapping& idMap)
{
AcDbBlockTableRecord *pSrcBlock = NULL;
acdbOpenObject(pSrcBlock,
srcBlockId,
AcDb::kForRead);
AcDbSortentsTable *pSortTab1 = NULL;
pSrcBlock->getSortentsTable(pSortTab1,
AcDb::kForRead,
true);
AcDbObjectIdArray oids;
pSortTab1->getFullDrawOrder(oids);
pSortTab1->close();
pSrcBlock->close();
AcDbBlockTableRecord *pTargetBlock = NULL;
acdbOpenObject(pTargetBlock,
targetBlockId,
AcDb::kForRead);
AcDbSortentsTable *pSortTab2 = NULL;
pTargetBlock->getSortentsTable(pSortTab2,
AcDb::kForWrite,
true);
AcDbObjectIdArray targetIds;
int len = oids.length();
for(int cnt = 0; cnt < len; cnt++)
{
AcDbIdPair idPair(oids.at(cnt),
AcDbObjectId::kNull,
true);
if (idMap.compute (idPair))
targetIds.append(idPair.value());
}
pSortTab2->setRelativeDrawOrder(targetIds);
pSortTab2->close();
pTargetBlock->close();
}