找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 839|回复: 2

[ARX程序]:各位高人帮个忙,有用过 AcApLayoutManager 这个类吗

[复制链接]
发表于 2007-6-1 16:51:33 | 显示全部楼层 |阅读模式

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

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

×
请各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
就是创建、或复制图纸空间的类
createLayout、copyLayout主要这两个函数怎么用
谢谢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2007-6-14 00:55:03 | 显示全部楼层

Re: [ARX程序]:各位高人帮个忙,有用过 AcApLayoutManager 这个类吗

最初由 ksbaidu 发布
[B]请各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
就是创建、或复制图纸空间的类
createLayout、copyLayout主要这两个函数怎么用
谢谢! [/B]

有的

  1.   [FONT=courier new]
  2. Acad::ErrorStatus
  3. CreateLayoutFromTemplate(
  4.       AcDbObjectId &layoutId,   
  5.       AcDbObjectId &blockTableRecId,
  6.       AcDbViewport*& pVP,
  7.       const char* dwtName,
  8.       const char* entryName
  9.       )
  10. {
  11.   Acad::ErrorStatus es;
  12.   AcDbDatabase *pDWTdb = new AcDbDatabase(false);
  13.   
  14.   es = pDWTdb->readDwgFile(dwtName);
  15.   if (es == Acad::eOk )
  16.   {
  17.     //get the layout dictionary
  18.     AcDbDictionary *pDict = NULL;
  19.     es = pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);
  20.    
  21.     AcDbObject *pObj = NULL;
  22.     AcDbLayout *pSrcLayout = NULL;
  23.     AcDbLayout *pNewLayout = NULL;
  24.    

  25.     //copy the layout entryName from the drawing template
  26.     //or you can use the AcDbDictionaryIterator to get the required AcDbLayout  from the database
  27.     es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
  28.     //close the dictionary
  29.     pDict->close();

  30.     if(es == Acad::eOk) // es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
  31.     {
  32.       pSrcLayout = AcDbLayout::cast(pObj);
  33.       //add new layout to the current document
  34.       AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
  35.       
  36.       //get the name to create a new layout
  37.       char* psName;
  38.       psName = pLayoutMan->getNextNewLayoutName();
  39.       
  40.       //create a new layout
  41.       pLayoutMan->setCreateViewports(Adesk::kTrue);
  42.       pLayoutMan->createLayout(psName, layoutId, blockTableRecId);
  43.       pNewLayout = pLayoutMan->findLayoutNamed(psName, TRUE);
  44.       //copy from the source layout in to the new layout
  45.       pNewLayout->copyFrom(pSrcLayout);
  46.       
  47.       //open the newlayout object to refresh the list
  48.       //this required to refresh the device list
  49.       pNewLayout->upgradeOpen();
  50.       AcDbPlotSettingsValidator *pPltValid = NULL;
  51.       pPltValid = acdbHostApplicationServices()->plotSettingsValidator();
  52.       pPltValid->refreshLists(pNewLayout);
  53.       
  54.       //close the layouts
  55.       pNewLayout->close();
  56.       pSrcLayout->close();
  57.       
  58.       //update the layout tabs using the layout manager
  59.       pLayoutMan->updateLayoutTabs();
  60.       
  61.       // copy entity from template
  62.       // Source BlockTableRecordId
  63.       AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
  64.       // Source BlockTableRecord
  65.       AcDbBlockTableRecord *pSource = 0;
  66.       // Open Source for Read
  67.       es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
  68.       if(es == Acad::eOk) // es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
  69.       {
  70.         AcDbBlockTableRecordIterator* pIter = 0;
  71.         pSource->newIterator(pIter);
  72.         AcDbObjectIdArray Idlist;
  73.         while(!pIter->done())
  74.         {
  75.           // Add all the entities to the list
  76.           AcDbEntity *pEnt = 0;
  77.           es = pIter->getEntity(pEnt, AcDb::kForRead);
  78.           if(es == Acad::eOk)
  79.           {
  80.             AcDbObjectId obj;
  81.             AcDbObjectId id = pEnt->objectId();
  82.             Idlist.append( id );
  83.             if((obj = pEnt->extensionDictionary()) != AcDbObjectId::kNull)
  84.             {
  85.               AcDbDictionary *pDict = 0;
  86.               acdbOpenObject(pDict, obj, AcDb::kForWrite);
  87.               pDict->setTreatElementsAsHard(Adesk::kTrue);
  88.               pDict->close();
  89.             }
  90.             pEnt->close();
  91.           }
  92.           pIter->step();
  93.         }
  94.         delete pIter;
  95.       

  96.         pSource->close();
  97.         
  98.         // New BlockTableRecordId
  99.         //AcDbObjectId newId = pNewLayout->getBlockTableRecordId();
  100.         // Set this Layout Current
  101.         //es = pLayoutMan->setCurrentLayoutId(newId);
  102.         es = pLayoutMan->setCurrentLayoutId(layoutId);
  103.         
  104.         AcDbDatabase *pNewDb;
  105.         es = pDWTdb->wblock( pNewDb, Idlist, AcGePoint3d::kOrigin);
  106.         
  107.         acdbHostApplicationServices()->workingDatabase()->insert(AcGeMatrix3d::kIdentity, pNewDb);
  108.         
  109.         delete pNewDb;
  110.       
  111.       }
  112.       
  113.       
  114.       // delete the damnnnnnnnnn- AcDbViewPort
  115.       AcDbBlockTableRecord *pTarget = 0;
  116.       // Open Source for Read
  117.       es = acdbOpenObject(pTarget, blockTableRecId, AcDb::kForRead);
  118.       if(es == Acad::eOk)
  119.       {
  120.         AcDbBlockTableRecordIterator* pIter = 0;
  121.         pTarget->newIterator(pIter);
  122.         bool bFirst = true;
  123.         while(!pIter->done())
  124.         {
  125.           // Add all the entities to the list
  126.           AcDbEntity *pEnt = 0;
  127.           es = pIter->getEntity(pEnt, AcDb::kForRead);
  128.          
  129.           if(es == Acad::eOk)
  130.           {
  131.             if (pEnt->isKindOf(AcDbViewport::desc()))
  132.             {
  133.               AcDbViewport *pVPort = (AcDbViewport *)pEnt;
  134.               
  135.               es = pVPort->upgradeOpen();
  136.               if (!pVPort->isOn() )
  137.               {
  138.                 if (bFirst)
  139.                 {
  140.                   pVPort->erase();
  141.                   bFirst = false;
  142.                 }
  143.                 else
  144.                 {
  145.                   pVPort->setOn();
  146.                   pVP = pVPort;
  147.                   
  148.                 }
  149.               }
  150.             }
  151.             pEnt->close();
  152.           }
  153.          
  154.           pIter->step();
  155.         }
  156.         pTarget->close();
  157.       }

  158.     }
  159.   }

  160.   delete pDWTdb;
  161.   
  162.   return es;   
  163. }

  164.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2007-6-20 20:29:54 | 显示全部楼层
谢谢rave
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-9-23 00:32 , Processed in 0.319432 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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