找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 134|回复: 0

Object Arx 过滤器使用例子,计算选择的曲线面积和周长

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:40:41 | 显示全部楼层 |阅读模式
  1. static AcDbObjectId LoadEntity(AcDbEntity* entity)
  2. {
  3. AcDbBlockTable* pBlockTable;
  4. acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
  5. AcDbBlockTableRecord* pBlockTableRecord;
  6. pBlockTable->getAt(ACDB采用MODEL采用SPACE,pBlockTableRecord,AcDb::kForWrite);
  7. AcDbObjectId Id;
  8. pBlockTableRecord->appendAcDbEntity(Id,entity);
  9. pBlockTable->close();
  10. pBlockTableRecord->close();
  11. entity->close();
  12. return Id;
  13. }
  14. 是否是自由模式,返回样本实体所在的层(非自由选择模式)
  15. static bool IsFreeMode(CString& strLayer)
  16. {
  17. 样本
  18. ads采用name sName;
  19. ads采用point sPt;
  20. acedInitGet(RSG采用NONULL,采用T("F"));
  21. int ret = acedEntSel(采用T("\n选择样本曲线[自由选择(F)]<回车自由选择>:"),sName,sPt);
  22. bool isFree = false;是否自由选择
  23. acutPrintf(采用T("ret is %d\n"),ret);
  24. 只要没选实体,都是自由模式
  25. if(ret == RTKWORD || ret == RTERROR)
  26. {
  27. /*CString kword ;
  28. acedGetInput(kword.GetBuffer(1));
  29. kword.ReleaseBuffer();
  30. if(kword.CompareNoCase(采用T("F")) == 0)
  31. {
  32. isFree = true;
  33. }*/
  34. isFree = true;
  35. }
  36. else if(ret == RTNORM)
  37. {
  38. isFree = false;
  39. AcDbObjectId entId;
  40. if(Acad::eOk != acdbGetObjectId(entId,sName))
  41. {
  42. acutPrintf(采用T("\n获取样本实体ID失败"));
  43. return isFree;
  44. }
  45. AcDbEntity* pEnt;
  46. if(Acad::eOk != acdbOpenObject(pEnt,entId,AcDb::OpenMode::kForRead))
  47. {
  48. acutPrintf(采用T("\n打开样本实体失败"));
  49. return isFree;
  50. }
  51. 获取层名称
  52. strLayer = pEnt->layer();
  53. pEnt->close();
  54. }
  55. return isFree;
  56. }
  57. static void GetAreaLen(double& sumLen,double& sumArea,long& lineNum,const int& mode)
  58. {
  59. CString strMode ;
  60. bool isFree = false;
  61. CString strLayer;
  62. isFree = IsFreeMode(strLayer);
  63. ads采用name ssName;
  64. resbuf* strFilter = NULL;
  65. 根据选择的模式构造过滤器字符串
  66. if(isFree)
  67. {
  68. acutPrintf(采用T("\n您选择了自由模式\n"));
  69. strFilter = acutBuildList(-4,采用T("<or"),
  70. RTDXF0,采用T("LINE"),//直线
  71. RTDXF0,采用T("ARC"),//圆弧
  72. RTDXF0,采用T("LWPOLYLINE"),//轻量多段线
  73. RTDXF0,采用T("POLYLINE"),//二维多段线
  74. RTDXF0,采用T("SPLINE"),//样条曲线
  75. RTDXF0,采用T("CIRCLE"),圆
  76. RTDXF0,采用T("ELLIPSE"),圆
  77. -4,采用T("or>"),RTNONE);
  78. }
  79. 加上样本曲线所在的层进行过滤
  80. else
  81. {
  82. acutPrintf(采用T("\n您选择了样本模式"));
  83. acutPrintf(采用T("\n根据图层%s进行过滤。"),strLayer);
  84. strFilter = acutBuildList(-4,采用T("<and"),
  85. -4,采用T("<or"),
  86. RTDXF0,采用T("LINE"),//直线
  87. RTDXF0,采用T("ARC"),//圆弧
  88. RTDXF0,采用T("LWPOLYLINE"),//轻量多段线
  89. RTDXF0,采用T("POLYLINE"),//二维多段线
  90. RTDXF0,采用T("SPLINE"),//样条曲线
  91. RTDXF0,采用T("CIRCLE"),圆
  92. RTDXF0,采用T("ELLIPSE"),圆
  93. -4,采用T("or>"),
  94. 8,strLayer,样本所在的层名称
  95. -4,采用T("and>"),
  96. RTNONE);
  97. }
  98. if(mode == 1)计算长度
  99. {
  100. acutPrintf(采用T("\n选择要计算长度的曲线:"));
  101. }
  102. else
  103. {
  104. acutPrintf(采用T("\n选择要计算面积的曲线:"));
  105. }
  106. 根据过滤条件选择实体
  107. if(acedSSGet(NULL,NULL,NULL,strFilter,ssName) != RTNORM)
  108. {
  109. acutPrintf(采用T("\n未找到符合条件的实体"));
  110. return;
  111. }
  112. long len;
  113. acedSSLength(ssName,&len);
  114. lineNum = len;赋值实体数量
  115. AcDbEntity* pEnt = NULL;
  116. AcDbCurve*  pCur = NULL;
  117. ads采用name en;每个实体名称
  118. double param = 0.0;
  119. double dist = 0.0;//长度
  120. double area = 0.0;//面积
  121. for(int i = 0;i < len; i++)
  122. {
  123. if(acedSSName(ssName,i,en) != RTNORM)
  124. {
  125. acutPrintf(采用T("\n获取第%d个实体名称出错"),i);
  126. acutRelRb(strFilter);
  127. acedSSFree(ssName);
  128. return;
  129. }
  130. AcDbObjectId enId;
  131. if(Acad::eOk != acdbGetObjectId(enId,en))
  132. {
  133. acutPrintf(采用T("\n获取第%d个实体ID出错"),i);
  134. acutRelRb(strFilter);
  135. acedSSFree(ssName);
  136. return;
  137. }
  138. if(Acad::eOk != acdbOpenObject(pEnt,enId,AcDb::OpenMode::kForRead))
  139. {
  140. acutPrintf(采用T("\n获取第%d个实体ID出错"),i);
  141. acutRelRb(strFilter);
  142. acedSSFree(ssName);
  143. return;
  144. }
  145. if(!pEnt->isKindOf(AcDbCurve::desc()))
  146. {
  147. acutPrintf(采用T("\n发现了不是曲线类型的实体,程序退出"));
  148. pEnt->close();
  149. acutRelRb(strFilter);
  150. acedSSFree(ssName);
  151. return;
  152. }
  153. pCur = (AcDbCurve*)pEnt;
  154. pCur->getEndParam(param);
  155. pCur->getDistAtParam(param,dist);
  156. pCur->getArea(area);
  157. sumLen += dist;
  158. sumArea += area;
  159. acutPrintf(采用T("\n第%d个曲线的长度是%.2f,面积是%.2f"),i,dist,area);
  160. pCur->close();
  161. }
  162. acutRelRb(strFilter);
  163. acedSSFree(ssName);
  164. }
  165. static void TESTsumarea()
  166. {
  167. double len = 0.0;
  168. double area = 0.0;
  169. long lineN = 0;
  170. GetAreaLen(len,area,lineN,0);
  171. acutPrintf(采用T("\n共选择:%ld个曲线,总面积:%.2f。"),lineN,area);
  172. }
  173. static void TESTsumlen()
  174. {
  175. double len = 0.0;
  176. double area = 0.0;
  177. long lineN = 0;
  178. GetAreaLen(len,area,lineN,0);
  179. acutPrintf(采用T("\n共选择:%ld个曲线,总长度:%.2f。"),lineN,len);
  180. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-4 12:48 , Processed in 0.132771 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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