//将当前dwg内的对象复制到另一个dwg文件中
AcDbDatabase * pDB=acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pBT1;
pDB->getBlockTable(pBT1,AcDb::kForRead);
AcDbBlockTableRecord *pBTR1;
pBT1->getAt(ACDB_MODEL_SPACE,pBTR1,AcDb::kForRead);
AcDbBlockTableRecordIterator * pBTRIt;
AcDbObjectIdArray objArr;
AcDbIdMapping idMap;
pBTR1->newIterator(pBTRIt);
pBTRIt->start();
for (;!pBTRIt->done();pBTRIt->step())
{
AcDbObjectId objID;
pBTRIt->getEntityId(objID);
objArr.append(objID);
//下面的代码要执行,到时整合
// for ( ; !pIT->done(); pIT->step()) {
// if (Acad::eOk == pIT->getEntityId( id )) {
// list.append( id );
//
// // There is a bug in ARX that causes extension dictionaries
// // to appear to be soft owners of their contents. This causes
// // the contents to be skipped during wblock. To fix this we
// // must explicitly tell the extension dictionary to be a hard
// // owner of it's entries.
// //
// AcDbEntity *pEnt;
// if ( Acad::eOk == pIT->getEntity(pEnt, AcDb::kForRead)) {
// AcDbObjectId obj;
// if ((obj = pEnt->extensionDictionary())
// != AcDbObjectId::kNull)
// {
// AcDbDictionary *pDict = NULL;
// acdbOpenObject(pDict, obj, AcDb::kForWrite);
// if (pDict) {
// pDict->setTreatElementsAsHard(Adesk::kTrue);
// pDict->close();
// }
// }
// pEnt->close();
// }
// }
// }
}
delete pBTRIt;
pBTR1->close();
pBT1->close();
AcDbDatabase* pTempDb=new AcDbDatabase();
idMap.setDestDb(pTempDb);
pTempDb->getSymbolTable(pBT1,AcDb::kForRead);
Acad::ErrorStatus e;
AcDbBlockTableRecord * pBTR2;
AcDbObjectId pSpaceObjID;
pBT1->getAt(ACDB_MODEL_SPACE,pSpaceObjID);
pBT1->close();
// pSpaceObjID=getBlockId(ACDB_PAPER_SPACE);
e=pTempDb->wblockCloneObjects(objArr,pSpaceObjID,idMap,AcDb::kDrcIgnore);
pTempDb->saveAs(_T("c:\\aaa.dwg"));
delete pTempDb;