天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
楼主: admin1

ARX关于块的相关疑难问题整理

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
 楼主| 发表于 2024-5-4 11:14:19 | 显示全部楼层
获取裁剪块的边界
  1. bool TransModelHelper::drawAPlineWithPropertiesFromBlockRef(AcGePoint2dArray pts, AcDbBlockReference* ref, double elevation, AcGeVector3d& normal)
  2. {
  3.         AcDbPolyline *pl = new AcDbPolyline;
  4.         AcDbObjectId owner;
  5.         pl->setDatabaseDefaults();
  6.         pl->setClosed(Adesk::kTrue);
  7.         pl->setThickness(0.0);
  8.         if (ref != NULL)
  9.         {
  10.                 owner = ref->ownerId();
  11.                 pl->setPropertiesFrom(ref);
  12.         }
  13.         pl->setNormal(normal);
  14.         for (int i = 0; i < pts.length(); i++)
  15.         {
  16.                 pl->addVertexAt(i, pts[i]);
  17.         }
  18.         pl->setElevation(elevation);
  19.         pl->setColorIndex(1); // Red
  20.         AcDbBlockTableRecord *rec = NULL;
  21.         acdbOpenObject(rec, owner, AcDb::kForWrite);
  22.         if (rec != NULL)
  23.         {
  24.                 AcDbObjectId id;
  25.                 rec->appendAcDbEntity(id, pl);
  26.                 pl->close();
  27.                 rec->close();
  28.         }
  29.         else
  30.         {
  31.                 delete pl;
  32.                 return false;
  33.         }
  34.         return true;
  35. }
  36. bool TransModelHelper::GetBlockClippingPolyline(ads采用name blk, AcGePoint3dArray& pts3d)
  37. {
  38.         BOOL ret = FALSE;
  39.         AcDbBlockReference *ref = NULL;
  40.         AcDbObjectId insId = AcDbObjectId::kNull;
  41.         acdbGetObjectId(insId, blk);
  42.         if (acdbOpenObject(ref, insId, AcDb::kForRead) != Acad::eOk)
  43.                 return ret;
  44.         // Find the clipping object (AcDbSpatialFilter) in the ExtDict of the BlockRef
  45.         AcDbObjectId extDicId = ref->extensionDictionary();
  46.         if (extDicId == AcDbObjectId::kNull)
  47.                 return ret;
  48.         AcDbDictionary *extDict = NULL, *acadFilterDict = NULL;
  49.         if (acdbOpenObject(extDict, extDicId, AcDb::kForRead) != Acad::eOk)
  50.                 return ret;
  51.         Acad::ErrorStatus err = extDict->getAt(采用T("ACAD采用FILTER"), (AcDbObject*&)acadFilterDict, AcDb::kForRead);
  52.         extDict->close();
  53.         if (err != Acad::eOk)
  54.                 return ret;
  55.         AcDbSpatialFilter *filter = NULL;
  56.         err = acadFilterDict->getAt(采用T("SPATIAL"), (AcDbObject*&)filter, AcDb::kForRead);
  57.         acadFilterDict->close();
  58.         if (err != Acad::eOk)
  59.                 return ret;
  60.         // Get the transform matrix stored in the XClip boundary
  61.         AcGeMatrix3d xformInBoundary = filter->getClipSpaceToWCSMatrix(xformInBoundary);
  62.         // and the transform of the BlockRef at the time when the Filter was set
  63.         AcGeMatrix3d xformRefOrig = filter->getOriginalInverseBlockXform(xformRefOrig);
  64.         // Get the transform matrix that the current BlockRef has, so, we can find the difference
  65.         // with the xformRefOrig
  66.         AcGeMatrix3d refMatrix = ref->blockTransform();
  67.         refMatrix = refMatrix.postMultBy(xformRefOrig);
  68.         // Calculate the final transform matrix which applies to the points
  69.         // returned from filter->getDefinition().
  70.         AcGeMatrix3d finalMatrix = refMatrix.postMultBy(xformInBoundary);
  71.        
  72.         AcGePoint2dArray pts;
  73.         //AcGePoint3dArray pts3d;
  74.         AcGeVector3d normal;
  75.         double elevation = 0, frontClip = 0, backClip = 0;
  76.         Adesk::Boolean enabled = false;
  77.         // Get all boundary points
  78.         if (filter->getDefinition(pts, normal, elevation, frontClip, backClip, enabled) == Acad::eOk)
  79.         {
  80.                 // Rectanglar boundary
  81.                 if (pts.length() == 2)
  82.                 {
  83.                         AcGePoint2d p1(pts[1].x, pts[0].y);
  84.                         AcGePoint2d p3(pts[0].x, pts[1].y);
  85.                         pts.insertAt(1, p1);
  86.                         pts.insertAt(3, p3);
  87.                 }
  88.                 // Transform all points with the transform matrix we calculated
  89.                 for (int i = 0; i < pts.length(); i++)
  90.                 {
  91.                         AcGePoint2d pt2d;
  92.                         AcGePoint3d pt3d;
  93.                         pt2d = pts[i];
  94.                         pt3d[0] = pt2d[0]; pt3d[1] = pt2d[1]; pt3d[2] = 0;
  95.                         pt3d.transformBy(finalMatrix);
  96.                         pts3d.append(pt3d);
  97.                 }
  98.         }
  99.         // Get the new normal and new ECS information for the polyline.
  100.         AcGeVector3d xfnorm = normal.transformBy(finalMatrix);
  101.         AcGeMatrix3d plineECS;
  102.         AcDbPolyline* pline = new AcDbPolyline();
  103.         pline->setNormal(xfnorm);
  104.         pline->getEcs(plineECS);
  105.         delete pline; pline = NULL;
  106.         AcGeMatrix3d plineECSInv = plineECS.inverse();
  107.         double xfelev = 0.0;
  108.         for (int i = 0; i < pts.length(); i++)
  109.         {
  110.                 pts[i].x = pts3d[i].x;
  111.                 pts[i].y = pts3d[i].y;
  112.                 if (i == 0)
  113.                         xfelev = pts3d[i].z;
  114.                 // Should be identical to within roundoff
  115.                 assert(fabs(xfelev - pts3d[i].z) < 1.0e-10);
  116.         }
  117.         // Show the boundary
  118. #ifdef 采用RELEASE采用WITHDEBUG
  119.         drawAPlineWithPropertiesFromBlockRef(pts, ref, xfelev, xfnorm);
  120. #endif
  121.         filter->close();
  122.         ref->close();
  123.         return true;
  124. }
  125. bool TransModelHelper::GetBlockClippingPolyline(AcDbObjectId idBlkRef, AcGePoint3dArray& pts3d)
  126. {
  127.         ads采用name snBlk;
  128.         acdbGetAdsName(snBlk, idBlkRef);
  129.         if (snBlk == NULL) return false;
  130.         return GetBlockClippingPolyline(snBlk, pts3d);
  131. }
  132. //test:
  133. //
  134. //ads采用point pt1;
  135. //ads采用name ent;
  136. //if (acedEntSel(采用T("请选择裁剪的块:"), ent, pt1) != RTNORM)
  137. //return;
  138. //
  139. //AcGePoint2dArray pts;
  140. //if (!GetBlockClippingPolyline(ent, pts))
  141. //return;
复制代码

 

 

 

 

ARX关于块的相关疑难问题整理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 08:11 , Processed in 0.112557 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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