找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 813|回复: 0

[图块] 获取块索引的XCLIP边界(Get the XCLIPped boundary of BlockReferences)

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-8 12:33:22 | 显示全部楼层 |阅读模式

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

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

×
问题:
How can I get the XCLIPped boundary of BlockReferences?


解答:
The boundary data is stored in an AcDbSpatialFilter object which in turn is stored in an entry name 'SPATIAL' in the extension dictionary 'ACAD_FILTER' of the XCLIPped block reference. More specifically, AcDbSpatialFilter::getDefinition() does the trick. Please bear one point in mind though. That is, it returns the points list of the XCLIPped boundary with the same coordinate system as the block definition. We need to transform those points by the block definition transform matrix manually. Refer to the ObjectARX Reference Guide for description of AcDbSpatialFilter::getClipSpaceToWCSMatrix() and AcDbSpatialFilter::getOriginalInverseBlockXform(). The full code is appended as follows:

  1.   // Draw a red polyline by the given points etc.
  2.   //--------------------------------------------------
  3.   static BOOL drawAPlineWithPropertiesFromBlockRef(AcGePoint2dArray pts,
  4.                  AcDbBlockReference* ref, double elevation, AcGeVector3d& normal)
  5.   {
  6.     AcDbPolyline *pl = new AcDbPolyline;
  7.     AcDbObjectId owner;
  8.     pl->setDatabaseDefaults();
  9.     pl->setClosed(Adesk::kTrue);
  10.     pl->setThickness(0.0);
  11.     if (ref != NULL) {
  12.         owner=ref->ownerId();
  13.         pl->setPropertiesFrom(ref);
  14.     }
  15.     pl->setNormal(normal);
  16.     for (int i=0; i < pts.length(); i++)
  17.     {
  18.         pl->addVertexAt(i, pts);
  19.     }
  20.     pl->setElevation(elevation);
  21.     pl->setColorIndex(1); // Red
  22.     AcDbBlockTableRecord *rec=NULL;
  23.     acdbOpenObject(rec, owner, AcDb::kForWrite);
  24.     if (rec != NULL)
  25.     {
  26.         AcDbObjectId id;
  27.         rec->appendAcDbEntity(id, pl);
  28.         pl->close();
  29.         rec->close();
  30.     }
  31.     else
  32.     {
  33.         delete pl;
  34.         return false;
  35.     }
  36.     return true;
  37.   } // End of drawAPlineWithPropertiesFromBlockRef()

  38.   // Get the boundary from a Block Reference given by the blk parameter.
  39.   // Transform that boundary to the WCS.
  40.   //-------------------------------------------------------------------
  41.   static BOOL GetBlockClippingPolyline(ads_name blk)
  42.   {
  43.     BOOL ret = FALSE;
  44.     AcDbBlockReference *ref = NULL;
  45.     AcDbObjectId insId = AcDbObjectId::kNull;
  46.     acdbGetObjectId(insId, blk);
  47.     if (acdbOpenObject(ref, insId, AcDb::kForRead) != Acad::eOk)
  48.       return ret;
  49.     // Find the clipping object (AcDbSpatialFilter) in the ExtDict of the BlockRef
  50.     AcDbObjectId extDicId = ref->extensionDictionary();
  51.     if( extDicId == AcDbObjectId::kNull )
  52.       return ret;
  53.     AcDbDictionary *extDict=NULL, *acadFilterDict=NULL;
  54.     if (acdbOpenObject(extDict, extDicId, AcDb::kForRead) != Acad::eOk)
  55.         return ret;
  56.     Acad::ErrorStatus err = extDict->getAt(_T("ACAD_FILTER"), (AcDbObject*&)acadFilterDict, AcDb::kForRead);
  57.     extDict->close();
  58.     if( err != Acad::eOk )
  59.         return ret;
  60.     AcDbSpatialFilter *filter=NULL;
  61.     err = acadFilterDict->getAt(_T("SPATIAL"), (AcDbObject*&)filter, AcDb::kForRead);
  62.     acadFilterDict->close();
  63.     if ( err != Acad::eOk)
  64.       return ret;
  65.     // Get the transform matrix stored in the XClip boundary
  66.     AcGeMatrix3d xformInBoundary = filter->getClipSpaceToWCSMatrix( xformInBoundary );
  67.     // and the transform of the BlockRef at the time when the Filter was set
  68.     AcGeMatrix3d xformRefOrig = filter->getOriginalInverseBlockXform( xformRefOrig );
  69.     // Get the transform matrix that the current BlockRef has, so, we can find the difference
  70.     //   with the xformRefOrig
  71.     AcGeMatrix3d refMatrix = ref->blockTransform();
  72.     refMatrix = refMatrix.postMultBy(xformRefOrig );
  73.     // Calculate the final transform matrix which applies to the points
  74.     // returned from filter->getDefinition().
  75.     AcGeMatrix3d finalMatrix = refMatrix.postMultBy(xformInBoundary);
  76.     AcGePoint2dArray pts;
  77.     AcGePoint3dArray pts3d;
  78.     AcGeVector3d normal;
  79.     double elevation = 0, frontClip = 0, backClip = 0;
  80.     Adesk::Boolean enabled  = false;
  81.     // Get all boundary points
  82.     if (filter->getDefinition(pts, normal, elevation, frontClip, backClip, enabled) == Acad::eOk)
  83.     {
  84.       // Rectanglar boundary
  85.       if (pts.length() == 2)
  86.       {
  87.         AcGePoint2d p1(pts[1].x, pts[0].y);
  88.         AcGePoint2d p3(pts[0].x, pts[1].y);
  89.         pts.insertAt(1, p1);
  90.         pts.insertAt(3, p3);
  91.       }
  92.       // Transform all points with the transform matrix we calculated
  93.       for(int i=0; i<pts.length(); i++)
  94.       {
  95.         AcGePoint2d pt2d;
  96.         AcGePoint3d pt3d;
  97.         pt2d = pts;
  98.         pt3d[0] = pt2d[0]; pt3d[1] = pt2d[1]; pt3d[2] = 0;
  99.         pt3d.transformBy(finalMatrix);
  100.         pts3d.append(pt3d);
  101.       }
  102.     }
  103.     // Get the new normal and new ECS information for the polyline.
  104.     AcGeVector3d xfnorm = normal.transformBy(finalMatrix);
  105.     AcGeMatrix3d plineECS;
  106.     AcDbPolyline* pline = new AcDbPolyline();
  107.     pline->setNormal(xfnorm);
  108.     pline->getEcs(plineECS);
  109.     delete pline; pline = NULL;
  110.     AcGeMatrix3d plineECSInv = plineECS.inverse();
  111.     double xfelev = 0.0;
  112.     for (int i = 0; i < pts.length(); i++)
  113.     {
  114.       pts.x = pts3d.x;
  115.       pts.y = pts3d.y;
  116.       if (i == 0)
  117.         xfelev = pts3d.z;
  118.       // Should be identical to within roundoff
  119.       assert(fabs(xfelev - pts3d.z) < 1.0e-10);
  120.     }
  121.     // Show the boundary
  122.     drawAPlineWithPropertiesFromBlockRef(pts, ref, xfelev, xfnorm);
  123.     filter->close();
  124.     ref->close();
  125.     return true;
  126.   } // End of GetBlockClippingPolyline()

  127.   // "MClip" test command for the GetBlockClippingPolyline() function.
  128. static void MMRCplusplus_MClip(void)
  129.   {
  130.     ads_name en;
  131.     AcGePoint3d pt;
  132.     if (acedEntSel(_T("\nSelect an INSERT clipped by XCLIP command: "), en, asDblArray(pt)) != RTNORM)
  133.     {
  134.       acutPrintf(_T("\nNothing selected"));
  135.       return;
  136.     }
  137.     assert(GetBlockClippingPolyline(en)==TRUE);
  138.   }


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

本版积分规则

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

GMT+8, 2024-4-29 11:52 , Processed in 0.289409 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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