- UID
- 55874
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-6-6
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2003-6-22 21:52:31
|
显示全部楼层
谢谢binbin的关心!问题我已经解决了。
wbcok和insert都要用到。
我看了帮助clones的例子。
这是现成的,
// Copies an external drawing into the current model space.
// This is the supported way: a combination of
// AcDbDatabase::insert and AcDbDatabase::wblock.
// First, we wblock the external database into a temporary
// in-memory database. We can't wblock directly into the
// current drawing, because wblock is destructive on the
// target database.
// Then we use insert to insert the temporary database into
// the current drawing. We can't use insert to insert the
// external drawing directly, because insert uses
// cheapClone, which moves the objects from the source to
// the target database.
//
// Using this approach, all the symbol table gets merged
// correctly into the current drawing database.
//
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;
}
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;
} |
|