|
发表于 2007-2-24 17:41:00
|
显示全部楼层
如下代码可以实现
void
clone3()
{
AcDbObjectId id;
AcDbObjectIdArray list;
AcDbDatabase extDatabase( Adesk::kFalse );
char dwgName[_MAX_PATH];
if (RTNORM != getFile( "Enter DWG name", "Select Drawing", "dwg",
dwgName ))
{
return;
}
if (Acad::eOk != extDatabase.readDwgFile( dwgName ))
{
acedAlert( "Error reading DWG!" );
return;
}
extDatabase.
AcDbBlockTable* pBT;
if (Acad::eOk != extDatabase.getSymbolTable( pBT, AcDb::kForRead ))
{
acedAlert( "Error getting BlockTable of DWG" );
return;
}
AcDbBlockTableRecord* pBTR;
Acad::ErrorStatus es = pBT->getAt( ACDB_MODEL_SPACE, pBTR, AcDb::kForRead );
pBT->close();
if (Acad::eOk != es) {
acedAlert( "Error getting model space of DWG" );
return;
}
AcDbBlockTableRecordIterator* pIT;
if (Acad::eOk != pBTR->newIterator( pIT )) {
acedAlert( "Error iterating model space of DWG" );
pBTR->close();
return;
}
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 pIT;
pBTR->close();
if (list.isEmpty()) {
acedAlert( "No entities found in model space of DWG" );
return;
}
AcDbDatabase *pTempDb;
if (Acad::eOk != extDatabase.wblock( pTempDb, list, AcGePoint3d::kOrigin ))
{
acedAlert( "wblock failed!" );
return;
}
if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()
->insert( AcGeMatrix3d::kIdentity, pTempDb ))
acedAlert( "insert failed!" );
delete pTempDb;
} |
|