找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 542|回复: 0

[ARX程序]:这是一个关于dwt文件读取的函数,大家帮忙看看,为什么wblock函数执行失败

[复制链接]
发表于 2004-8-4 09:22:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. void createLayoutFromDwt(CString filename)
  2. {
  3.         //read drawing database from the DWT file
  4.         Acad::ErrorStatus mEs;
  5.         AcDbDatabase *pDWTdb = new AcDbDatabase(false);

  6.         if (Acad::eOk == pDWTdb->readDwgFile(filename))
  7.         {
  8.                 //get the layout dictionary
  9.                 AcDbDictionary *pDict = NULL;
  10.                 pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);

  11.                 AcDbObject *pObj = NULL;
  12.                 AcDbLayout *pSrcLayout = NULL;
  13.                 AcDbLayout *pNewLayout = NULL;

  14.                 AcDbDictionaryIterator* pDictIter= pDict->newIterator();
  15.                 //close the dictionary
  16.                 pDict->close();

  17.                 for (; !pDictIter->done(); pDictIter->next())
  18.                 {
  19.                         // Get the current record, open it for write
  20.                         mEs = pDictIter->getObject((AcDbObject*&)pObj,AcDb::kForWrite);
  21.                         if(mEs == Acad::eOk)
  22.                         {
  23.                                 pSrcLayout = AcDbLayout::cast(pObj);
  24.                                 //add new layout to the current document
  25.                                 AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
  26.                                 AcDbObjectId LayoutID,BTRId;

  27.                                 //get the name to create a new layout
  28.                                 char* psName;
  29.                                 psName = pLayoutMan->getNextNewLayoutName();

  30.                                 //create a new layout
  31.                                 pLayoutMan->createLayout(psName,LayoutID,BTRId);
  32.                                 pNewLayout = pLayoutMan->findLayoutNamed(psName,TRUE);
  33.                                 //copy from the source layout in to the new layout
  34.                                 pNewLayout->copyFrom(pSrcLayout);

  35.                                 // Source BlockTableRecordId
  36.                                 AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
  37.                                 // Source BlockTableRecord
  38.                                 AcDbBlockTableRecord *pSource = 0;
  39.                                 // Open Source for Read
  40.                                 Acad::ErrorStatus es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
  41.                                 if(es == Acad::eOk)
  42.                                 {
  43.                                         AcDbBlockTableRecordIterator* pIterator = 0;
  44.                                         pSource->newIterator(pIterator);
  45.                                         AcDbObjectIdArray Idlist;
  46.                                         while(!pIterator->done())
  47.                                         {
  48.                                                 // Add all the entities to the list
  49.                                                 AcDbEntity *pEnt = 0;
  50.                                                 es = pIterator->getEntity(pEnt, AcDb::kForRead);
  51.                                                 if(es == Acad::eOk)
  52.                                                 {
  53.                                                         AcDbObjectId obj;
  54.                                                         AcDbObjectId id = pEnt->objectId();
  55.                                                         Idlist.append( id );
  56.                                                         if((obj = pEnt->extensionDictionary()) != AcDbObjectId::kNull)
  57.                                                         {
  58.                                                                 AcDbDictionary *pDict = 0;
  59.                                                                 acdbOpenObject(pDict, obj, AcDb::kForWrite);
  60.                                                                 pDict->setTreatElementsAsHard(Adesk::kTrue);
  61.                                                                 pDict->close();
  62.                                                         }
  63.                                                         pEnt->close();
  64.                                                 }
  65.                                                 pIterator->step();
  66.                                         }
  67.                                         delete pIterator;
  68.                                         pSource->close();

  69.                                         // New BlockTableRecordId
  70.                                         AcDbObjectId newId = pNewLayout->getBlockTableRecordId();
  71.                                         // Set this Layout Current
  72.                                         pLayoutMan->setCurrentLayoutId(newId);

  73.                                         AcDbDatabase *pNewDb = new AcDbDatabase;
  74.                                         if(pDWTdb->wblock( pNewDb, Idlist, AcGePoint3d::kOrigin) != Acad::eOk)
  75.                                         {
  76.                                                 //close the layouts
  77.                                                 pNewLayout->close();
  78.                                                 pSrcLayout->close();
  79.                                                 continue;
  80.                                         }
  81.                                         acdbCurDwg()->insert(AcGeMatrix3d::kIdentity, pNewDb);
  82.                                         delete pNewDb;
  83.                                 }

  84.                                 //open the newlayout object to refresh the list
  85.                                 //this required to refresh the device list
  86.                                 pNewLayout->upgradeOpen();
  87.                                 AcDbPlotSettingsValidator *pPltValid = NULL;
  88.                                 pPltValid = acdbHostApplicationServices()->plotSettingsValidator();
  89.                                 pPltValid->refreshLists(pNewLayout);

  90.                                 //close the layouts
  91.                                 pNewLayout->close();
  92.                                 pSrcLayout->close();

  93.                                 //update the layout tabs using the layout manager
  94.                                 pLayoutMan->updateLayoutTabs();
  95.                         }
  96.                 }
  97.                 delete pDictIter;
  98.         }
  99.         delete pDWTdb;
  100. }
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 21:56 , Processed in 0.299944 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表