设为首页收藏本站

晓东CAD家园-论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 155|回复: 0

[图块] AcDbBlockReference::explode 失败

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-2-2 10:00:01 | 显示全部楼层 |阅读模式

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

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

x
AcDbBlockReference::explode fails

问题:

Why does AcDbBlockReference::explode produce incorrect results if there are
AcDbText or AcDbAttribute definition entities in the block that is exploded?

解答:

This isa known problem that is desribed in DevNote #TS36113.
AcDbBlockReference::explode internally calls AcDbText::getTransformedCopy that
produces incorrect results. The code below uses the code in DevNote #TS36113 to
explode an AcDbBlockReference correctly.

  1. Acad::ErrorStatus safeExplode(const AcDbBlockReference* pRef,AcDbVoidPtrArray&entitySet)
  2. {  
  3. AcDbBlockTableRecord* pBTR;
  4. Acad::ErrorStatus es;  
  5. if ((es = acdbOpenAcDbObject((AcDbObject*&)pBTR, pRef->blockTableRecord(), AcDb::kForRead)) == Acad::eOk)
  6. {   
  7.   AcDbBlockTableRecordIterator* pIterator;
  8.   if (pBTR->newIterator(pIterator) == Acad::eOk)
  9.   {  
  10.    AcGeMatrix3d xform = pRef->blockTransform();   
  11.    AcGePoint3d pt3dBlkOrigin = pBTR->origin();  
  12.    if (pt3dBlkOrigin != AcGePoint3d::kOrigin)
  13.    {     
  14.     AcGeVector3d xformOrigin = xform.translation();
  15.     AcGeVector3d vectorOrigin(pt3dBlkOrigin.x,pt3dBlkOrigin.y,0.0);  
  16.     vectorOrigin.transformBy(xform);
  17.     xformOrigin -= vectorOrigin;   
  18.     xform.setTranslation(xformOrigin);   
  19.    }   
  20.    pIterator->start();   
  21.    while (!pIterator->done())
  22.    {     
  23.     AcDbEntity* pEntity;
  24.     if (pIterator->getEntity(pEntity, AcDb::kForRead) == Acad::eOk)
  25.     {
  26.       // If pEntity does not implement getTransformedCopy()  
  27.       // or explode() methods, we should simply ignore
  28.       // that entity and continue to step into next entity
  29.       // instead of exit prematurely. Most operations such
  30.       // as BHATCH depends on complete iteration through  
  31.       // the entire block entities.      
  32.       AcDbEntity* pNewEntity;
  33.       AcDbText* pText =NULL;   
  34.       if (pText=AcDbText::cast(pEntity))  
  35.        es = AdskUtil::safeGetTransformedCopy(pText,xform, pNewEntity);      
  36.       else
  37.       es = pEntity->getTransformedCopy(xform, pNewEntity);
  38.       if (es==Acad::eOk)
  39.       {
  40.       entitySet.append(pNewEntity);
  41.       }
  42.       else if (Acad::eExplodeBeforeTransform == es)
  43.       {
  44.       AcDbVoidPtrArray explSet;  
  45.       if (Acad::eOk == pEntity->explode(explSet))
  46.       {
  47.        for (int i = 0; i < explSet.length(); i++)
  48.        {         
  49.         AcDbEntity* pObj = (AcDbEntity*)explSet;
  50.         if (Acad::eOk == pObj->getTransformedCopy( xform, pNewEntity))
  51.         {     
  52.          entitySet.append(pNewEntity);   
  53.         }        
  54.         delete pObj;     
  55.        }  
  56.       }  
  57.      }
  58.      else if (Acad::eCopyFailed == es)
  59.      {            
  60.       AcDbVoidPtrArray explSet;   
  61.       if (Acad::eOk == pEntity->explode(explSet))
  62.       {            
  63.        for (int i = 0; i < explSet.length(); i++)     
  64.        {           
  65.         AcDbEntity* pObj = (AcDbEntity*)explSet;
  66.         if (Acad::eOk == pObj->transformBy(xform))
  67.         {         
  68.          entitySet.append(pObj);
  69.         }         
  70.        }   
  71.       }     
  72.      }     
  73.      pEntity->close();
  74.     }  
  75.     pIterator->step();
  76.    }   
  77.    delete pIterator;
  78.   }  
  79.   pBTR->close();
  80. }
  81. return es;
  82. }


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

本版积分规则

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

GMT+8, 2021-3-2 06:07 , Processed in 0.087699 second(s), 12 queries , Gzip On, WinCache On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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