|
复制图纸空间的视口到另一个dwg文件中,wblockcloneobjects对无法复制视口,原因还不清楚,只能用wblock,思想是将选定的视口wblock做块到一个中间database,然后再将块插入目的database的图纸空间,最后炸开即可
AcDbDatabase *pDbMid=new AcDbDatabase;
ads_name name;
ads_point pnt;
AcDbEntity * pEnt;
int i;
Acad::ErrorStatus es;
acedEntSel(_T("选择一个视口\n"),name,pnt);
AcDbObjectId objId,dicObj;
acdbGetObjectId(objId,name);
AcDbObjectIdArray arrID;
arrID.append(objId);
acedEntSel(_T("选择一个视口\n"),name,pnt);
acdbGetObjectId(objId,name);
arrID.append(objId);
//将扩展字典改为硬拥有,否则写块出去后会丢失
AcDbObjectId tempObjId;
for (i=0;i<arrID.length();i++)
{undefined
if(Acad::eOk==(es=acdbOpenObject(pEnt,arrID[i],AcDb::kForWrite))){undefined
AcDbObjectId obj;
if ((obj = pEnt->extensionDictionary())
!= AcDbObjectId::kNull)
{undefined
AcDbDictionary *pDict = NULL;
acdbOpenObject(pDict, obj, AcDb::kForWrite);
if (pDict) {undefined
pDict->setTreatElementsAsHard(Adesk::kTrue);
pDict->close();
}
}
pEnt->close();
}
}
AcGePoint3d base(0,0,0);
acdbHostApplicationServices()->workingDatabase()->wblock(pDbMid,arrID,base);
AcDbDatabase *pDbDest=new AcDbDatabase;
AcDbObjectId blkId;
es= pDbDest->insert(blkId,_T("dddddddd"),pDbMid); //块名要起一个唯一的,按guid可以
AcDbBlockReference *pBlkR=new AcDbBlockReference;
AcDbBlockTable *pBT;
pDbDest->getSymbolTable(pBT,AcDb::kForWrite);
AcDbObjectId blkObjId,spaceID;
AcDbBlockTableRecord *pBpr;
pBT->getAt(_T("dddddddd"),blkObjId);
pBT->getAt(ACDB_PAPER_SPACE,pBpr,AcDb::kForWrite);
pBlkR->setBlockTableRecord(blkObjId); //设置块参照
AcDbVoidPtrArray pExplodeEntArr;
pBlkR->explode(pExplodeEntArr); //炸开块
for (i=0;i<pExplodeEntArr.length();i++)
{undefined
AcDbEntity * pEnt=(AcDbEntity*)pExplodeEntArr[i];
pBpr->appendAcDbEntity(pEnt);
pEnt->close();
}
pBlkR->erase();
pBlkR->close();
pBpr->close();
//插入完成后把块表删掉
pBT->getAt(_T("dddddddd"),pBpr,AcDb::kForWrite);
pBpr->erase();
pBpr->close();
pBT->close();
pDbDest->saveAs(_T("c:\\rrrrrrr.dwg"));
delete pBlkR;
delete pDbDest;
delete pDbMid;
如果需要,再把源database中的图纸空间和模型空间的其他非视口对象wblcokcloneobjects到目的database,就
完成整个带视口的dwg文件的复制了.
— |
|