- UID
- 2299
- 积分
- 465
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-31
- 最后登录
- 1970-1-1
|
发表于 2007-6-14 00:55:03
|
显示全部楼层
Re: [ARX程序]:各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
最初由 ksbaidu 发布
[B]请各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
就是创建、或复制图纸空间的类
createLayout、copyLayout主要这两个函数怎么用
谢谢! [/B]
有的
- [FONT=courier new]
- Acad::ErrorStatus
- CreateLayoutFromTemplate(
- AcDbObjectId &layoutId,
- AcDbObjectId &blockTableRecId,
- AcDbViewport*& pVP,
- const char* dwtName,
- const char* entryName
- )
- {
- Acad::ErrorStatus es;
- AcDbDatabase *pDWTdb = new AcDbDatabase(false);
-
- es = pDWTdb->readDwgFile(dwtName);
- if (es == Acad::eOk )
- {
- //get the layout dictionary
- AcDbDictionary *pDict = NULL;
- es = pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);
-
- AcDbObject *pObj = NULL;
- AcDbLayout *pSrcLayout = NULL;
- AcDbLayout *pNewLayout = NULL;
-
- //copy the layout entryName from the drawing template
- //or you can use the AcDbDictionaryIterator to get the required AcDbLayout from the database
- es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
- //close the dictionary
- pDict->close();
- if(es == Acad::eOk) // es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
- {
- pSrcLayout = AcDbLayout::cast(pObj);
- //add new layout to the current document
- AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
-
- //get the name to create a new layout
- char* psName;
- psName = pLayoutMan->getNextNewLayoutName();
-
- //create a new layout
- pLayoutMan->setCreateViewports(Adesk::kTrue);
- pLayoutMan->createLayout(psName, layoutId, blockTableRecId);
- pNewLayout = pLayoutMan->findLayoutNamed(psName, TRUE);
- //copy from the source layout in to the new layout
- pNewLayout->copyFrom(pSrcLayout);
-
- //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();
-
- // copy entity from template
- // Source BlockTableRecordId
- AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
- // Source BlockTableRecord
- AcDbBlockTableRecord *pSource = 0;
- // Open Source for Read
- es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
- if(es == Acad::eOk) // es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
- {
- AcDbBlockTableRecordIterator* pIter = 0;
- pSource->newIterator(pIter);
- AcDbObjectIdArray Idlist;
- while(!pIter->done())
- {
- // Add all the entities to the list
- AcDbEntity *pEnt = 0;
- es = pIter->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();
- }
- pIter->step();
- }
- delete pIter;
-
- pSource->close();
-
- // New BlockTableRecordId
- //AcDbObjectId newId = pNewLayout->getBlockTableRecordId();
- // Set this Layout Current
- //es = pLayoutMan->setCurrentLayoutId(newId);
- es = pLayoutMan->setCurrentLayoutId(layoutId);
-
- AcDbDatabase *pNewDb;
- es = pDWTdb->wblock( pNewDb, Idlist, AcGePoint3d::kOrigin);
-
- acdbHostApplicationServices()->workingDatabase()->insert(AcGeMatrix3d::kIdentity, pNewDb);
-
- delete pNewDb;
-
- }
-
-
- // delete the damnnnnnnnnn- AcDbViewPort
- AcDbBlockTableRecord *pTarget = 0;
- // Open Source for Read
- es = acdbOpenObject(pTarget, blockTableRecId, AcDb::kForRead);
- if(es == Acad::eOk)
- {
- AcDbBlockTableRecordIterator* pIter = 0;
- pTarget->newIterator(pIter);
- bool bFirst = true;
- while(!pIter->done())
- {
- // Add all the entities to the list
- AcDbEntity *pEnt = 0;
- es = pIter->getEntity(pEnt, AcDb::kForRead);
-
- if(es == Acad::eOk)
- {
- if (pEnt->isKindOf(AcDbViewport::desc()))
- {
- AcDbViewport *pVPort = (AcDbViewport *)pEnt;
-
- es = pVPort->upgradeOpen();
- if (!pVPort->isOn() )
- {
- if (bFirst)
- {
- pVPort->erase();
- bFirst = false;
- }
- else
- {
- pVPort->setOn();
- pVP = pVPort;
-
- }
- }
- }
- pEnt->close();
- }
-
- pIter->step();
- }
- pTarget->close();
- }
- }
- }
- delete pDWTdb;
-
- return es;
- }
- [/FONT]
|
|