|
static void Command3(void)
{
// Add your code for command ZHPCDC.TEST here
Acad::ErrorStatus es;
CString strTargetFileFullPath = TEXT("D:\\test.dwg");
//create the new file
AcDbDatabase *pNewDb = new AcDbDatabase(true, false);
es = pNewDb->saveAs(strTargetFileFullPath);
delete pNewDb;
// get the targetDb, sourceDb and tempDb
AcDbDatabase *pTargetDb = new AcDbDatabase(false);
pTargetDb->readDwgFile(strTargetFileFullPath);
AcDbDatabase *pSourceDb = acdbHostApplicationServices()->workingDatabase();
AcDbDatabase *pTempDb = new AcDbDatabase(true, true);
es = pSourceDb->wblock(pTempDb);
// get the entities that need clone
AcDbObjectIdArray idsNeedClone;
AcDbBlockTable *pBlkTbl = NULL;
pTempDb->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd = NULL;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
pBlkTbl->close();
AcDbBlockTableRecordIterator *it = NULL;
pBlkTblRcd->newIterator(it);
for (it->start(); !it->done(); it->step())
{
AcDbObjectId id;
if (Acad::eOk != it->getEntityId(id)) continue;
idsNeedClone.append(id);
}
delete it;
pBlkTblRcd->close();
// clone from tempDb to targetDb
pTempDb->wblock(pTargetDb, idsNeedClone, AcGePoint3d::kOrigin, AcDb::kDrcReplace);
//redraw the entities in targetDb and saveas
RedrawAllEntitys(pTargetDb);
es = pTargetDb->closeInput(true);
es = acdbSaveAs2004(pTargetDb, strTargetFileFullPath);
delete pTargetDb;
delete pTempDb;
} |
|