- UID
- 71826
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-8-12
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- void createLayoutFromDwt(CString filename)
- {
- //read drawing database from the DWT file
- Acad::ErrorStatus mEs;
- AcDbDatabase *pDWTdb = new AcDbDatabase(false);
- if (Acad::eOk == pDWTdb->readDwgFile(filename))
- {
- //get the layout dictionary
- AcDbDictionary *pDict = NULL;
- pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);
- AcDbObject *pObj = NULL;
- AcDbLayout *pSrcLayout = NULL;
- AcDbLayout *pNewLayout = NULL;
- AcDbDictionaryIterator* pDictIter= pDict->newIterator();
- //close the dictionary
- pDict->close();
- for (; !pDictIter->done(); pDictIter->next())
- {
- // Get the current record, open it for write
- mEs = pDictIter->getObject((AcDbObject*&)pObj,AcDb::kForWrite);
- if(mEs == Acad::eOk)
- {
- pSrcLayout = AcDbLayout::cast(pObj);
- //add new layout to the current document
- AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
- AcDbObjectId LayoutID,BTRId;
- //get the name to create a new layout
- char* psName;
- psName = pLayoutMan->getNextNewLayoutName();
- //create a new layout
- pLayoutMan->createLayout(psName,LayoutID,BTRId);
- pNewLayout = pLayoutMan->findLayoutNamed(psName,TRUE);
- //copy from the source layout in to the new layout
- pNewLayout->copyFrom(pSrcLayout);
- // Source BlockTableRecordId
- AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
- // Source BlockTableRecord
- AcDbBlockTableRecord *pSource = 0;
- // Open Source for Read
- Acad::ErrorStatus es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
- if(es == Acad::eOk)
- {
- AcDbBlockTableRecordIterator* pIterator = 0;
- pSource->newIterator(pIterator);
- AcDbObjectIdArray Idlist;
- while(!pIterator->done())
- {
- // Add all the entities to the list
- AcDbEntity *pEnt = 0;
- es = pIterator->getEntity(pEnt, AcDb::kForRead);
- if(es == Acad::eOk)
- {
- AcDbObjectId obj;
- AcDbObjectId id = pEnt->objectId();
- Idlist.append( id );
- if((obj = pEnt->extensionDictionary()) != AcDbObjectId::kNull)
- {
- AcDbDictionary *pDict = 0;
- acdbOpenObject(pDict, obj, AcDb::kForWrite);
- pDict->setTreatElementsAsHard(Adesk::kTrue);
- pDict->close();
- }
- pEnt->close();
- }
- pIterator->step();
- }
- delete pIterator;
- pSource->close();
- // New BlockTableRecordId
- AcDbObjectId newId = pNewLayout->getBlockTableRecordId();
- // Set this Layout Current
- pLayoutMan->setCurrentLayoutId(newId);
- AcDbDatabase *pNewDb = new AcDbDatabase;
- if(pDWTdb->wblock( pNewDb, Idlist, AcGePoint3d::kOrigin) != Acad::eOk)
- {
- //close the layouts
- pNewLayout->close();
- pSrcLayout->close();
- continue;
- }
- acdbCurDwg()->insert(AcGeMatrix3d::kIdentity, pNewDb);
- delete pNewDb;
- }
- //open the newlayout object to refresh the list
- //this required to refresh the device list
- pNewLayout->upgradeOpen();
- AcDbPlotSettingsValidator *pPltValid = NULL;
- pPltValid = acdbHostApplicationServices()->plotSettingsValidator();
- pPltValid->refreshLists(pNewLayout);
- //close the layouts
- pNewLayout->close();
- pSrcLayout->close();
- //update the layout tabs using the layout manager
- pLayoutMan->updateLayoutTabs();
- }
- }
- delete pDictIter;
- }
- delete pDWTdb;
- }
|
|