天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 119|回复: 0

OBJECT ARX 绘制常用图形 总结

[复制链接]
  • TA的每日心情
    开心
    昨天 06:36
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-5-2 22:46:51 | 显示全部楼层 |阅读模式
    1. 将图形加载显示到CAD===================
    2. static AcDbObjectId LoadEntity(AcDbEntity* entity){
    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 void AddOrdinate(AcGePoint3d ptStart,AcGePoint3d ptEnd,
    16. CString text){
    17. AcDbOrdinateDimension* pDim = new
    18. AcDbOrdinateDimension(true,ptStart,ptEnd,text);
    19. LoadEntity(pDim);
    20. }
    21. 画线====================
    22. static void TESTlineCmd()
    23. {
    24. //acutPrintf(采用T("\nHello"));
    25. ads采用point inputStart;
    26. ads采用point inputEnd;
    27. AcGePoint3d ptStart;
    28. AcGePoint3d ptEnd;
    29. 用户输入要画的坐标
    30. if(acedGetPoint(NULL,采用T("start point"),inputStart) != RTNORM){
    31. return;
    32. }
    33. ptStart[X] = inputStart[X];
    34. ptStart[Y] = inputStart[Y];
    35. ptStart[Z] = inputStart[Z];
    36. if(acedGetPoint(NULL,采用T("end point"),inputEnd) != RTNORM){
    37. return;
    38. }
    39. ptEnd[X] = inputEnd[X];
    40. ptEnd[Y] = inputEnd[Y];
    41. ptEnd[Z] = inputEnd[Z];
    42. AcDbLine* pLine = new AcDbLine(ptStart,ptEnd);
    43. pLine->setColorIndex(2);
    44. LoadEntity(pLine);
    45. AddOrdinate(ptStart,ptEnd,采用T("hi"));
    46. //AfxMessageBox(采用T("命令画了一条线"));
    47. }
    48. 画圆形==========================
    49. static void TESTcirclecmd(){
    50. 垂直平面法向量
    51. AcGeVector3d vec(0,0,1);
    52. 圆心
    53. AcGePoint3d ptCenter(100,100,100);
    54. AcDbCircle* pCircle = new AcDbCircle(ptCenter,vec,1000);
    55. LoadEntity(pCircle);
    56. }
    57. 画圆弧================================
    58. static void TESTarccmd(){
    59. AcGeVector3d vec(0,0,1);
    60. AcGePoint3d ptCenter(500,500,500);
    61. AcDbArc* pArc = new AcDbArc(ptCenter,vec,700,0,90);
    62. LoadEntity(pArc);
    63. }
    64. 画多线段============================
    65. static void TESTpolycmd(){
    66. 构造多点数组
    67. AcGePoint2dArray points;
    68. AcGePoint2d pt1(1000, 1000);
    69. AcGePoint2d pt2(2000, 1800);
    70. AcGePoint2d pt3(500, 2000);
    71. AcGePoint2d pt4(3000, 5000);
    72. points.append(pt1);
    73. points.append(pt2);
    74. points.append(pt3);
    75. points.append(pt4);
    76. 绘制多点线段
    77. AcDbPolyline* pl = new AcDbPolyline(points.length());
    78. for(int i = 0;i < points.length();i ++){
    79. pl->addVertexAt(i,points.at(i),0,0.5,0.5);
    80. }
    81. LoadEntity(pl);
    82. }
    83. 绘制POLY3d线段====================
    84. static void TESTpoly3dcmd(){
    85. 构造多点数组
    86. AcGePoint3dArray points;
    87. AcGePoint3d pt1(10, 10,10);
    88. AcGePoint3d pt2(20, 10,20);
    89. AcGePoint3d pt3(20, 20,30);
    90. points.append(pt1);
    91. points.append(pt2);
    92. points.append(pt3);
    93. 绘制多点线段
    94. AcDb3dPolyline* pl = new AcDb3dPolyline(AcDb::Poly3dType::k3dSimplePoly,points);
    95. LoadEntity(pl);
    96. }
    97. 绘制椭圆=========================
    98. static void TESTellipsecmd(){
    99. 椭圆焦点
    100. /* AcGePoint2d p1(400,400);
    101. AcGePoint2d p2(800,400);*/
    102. 中心点
    103. AcGePoint3d ptCenter(600,400,0);
    104. AcGeVector3d vecNormal(0,0,1);
    105. 长轴
    106. AcGeVector3d majorAxis(1000,0,0);
    107. 通过曲率确定短轴长度
    108. double ratio = 0.6;
    109. AcDbEllipse* ae = new AcDbEllipse(/*AcGePoint3d::kOrigin*/ptCenter,vecNormal,majorAxis,
    110. ratio);
    111. LoadEntity(ae);
    112. }
    113. 创建样条曲线================
    114. static void TESTsplinecmd(){
    115. AcGePoint3d p1(0,0,0),p2(200,600,0),p3(1200,1600,0),
    116. p4(2000,2000,0);
    117. AcGePoint3dArray points;
    118. points.append(p1);
    119. points.append(p2);
    120. points.append(p3);
    121. points.append(p4);
    122. AcDbSpline* as = new AcDbSpline(points);
    123. LoadEntity(as);
    124. }
    125. 创建面域(把用直线创建的闭合图形,生成一个图形的对象)
    126. static void TESTregioncmd(){
    127. ads采用name ss;
    128. 提示用户选择对象
    129. int rt = acedSSGet(NULL,NULL,NULL,NULL,ss);
    130. AcDbObjectIdArray ids;
    131. if(rt == RTNORM){
    132. long len;
    133. 获得对象个数
    134. acedSSLength(ss,&len);
    135. for(int i = 0;i < len;i ++){
    136. 先从对象中得到名字
    137. ads采用name ent;
    138. acedSSName(ss,i,ent);
    139. 再从名字中取出ID
    140. AcDbObjectId objId;
    141. acdbGetObjectId(objId,ent);
    142. ids.append(objId);
    143. }
    144. }
    145. acedSSFree(ss);
    146. 得到objId数组之后,开始画区域
    147. CreateRegion(ids);
    148. }
    149. 绘制面域
    150. static AcDbObjectIdArray  CreateRegion(AcDbObjectIdArray ids){
    151. AcDbObjectIdArray regionIds;
    152. AcDbVoidPtrArray curves;
    153. AcDbVoidPtrArray regions;
    154. AcDbEntity* pEnt;
    155. AcDbRegion* pRegion;
    156. for(int i = 0;i < ids.length();i ++){
    157. acdbOpenAcDbEntity(pEnt,ids.at(i),AcDb::kForRead);
    158. if(pEnt->isKindOf(AcDbCurve::desc())){
    159. curves.append(static采用cast<void*>(pEnt));
    160. }
    161. }
    162. Acad::ErrorStatus es = AcDbRegion::createFromCurves(curves,regions);
    163. if(es == Acad::eOk){
    164. for(int i = 0;i < regions.length();i ++){
    165. pRegion = static采用cast<AcDbRegion*>(regions[i]);
    166. pRegion->setDatabaseDefaults();
    167. AcDbObjectId regionId = LoadEntity(pRegion);
    168. regionIds.append(regionId);
    169. }
    170. CString tipStr ;
    171. tipStr.Format(采用T("\n已成功创建面域:%d个"),regions.length());
    172. acutPrintf(tipStr);
    173. }
    174. else{
    175. for(int i = 0;i < regions.length();i ++){
    176. delete (AcRxObject*)regions[i];
    177. }
    178. }
    179. for(int i = 0;i < ids.length();i ++){
    180. pEnt = static采用cast<AcDbEntity*>(curves[i]);
    181. pEnt->close();
    182. }
    183. return regionIds;
    184. }
    185. //绘制文字===================
    186. static void TESTtextcmd(){
    187. AcGePoint3d ptInsert(0,400,0);
    188. AcDbMText* pMText = new AcDbMText();
    189. 设置多行文字特性
    190. pMText->setContents(采用T("hello!!"));
    191. pMText->setLocation(ptInsert);
    192. pMText->setTextHeight(1000);
    193. pMText->setWidth(1000);
    194. pMText->setAttachment(AcDbMText::kBottomLeft);
    195. LoadEntity(pMText);
    196. }
    197. 创建填充======================
    198. static void TESThatchcmd(){
    199. 提示用户选择填充边界
    200. ads采用name ss;
    201. int rt = acedSSGet(NULL,NULL,NULL,NULL,ss);
    202. AcDbObjectIdArray objIds;
    203. if(rt == RTNORM){
    204. long len;
    205. acedSSLength(ss,&len);
    206. for(int i = 0;i < len;i ++){
    207. ads采用name ent;
    208. acedSSName(ss,i,ent);
    209. AcDbObjectId objId;
    210. acdbGetObjectId(objId,ent);
    211. objIds.append(objId);
    212. }
    213. }
    214. acedSSFree(ss);
    215. 选择完毕,绘制填充
    216. Acad::ErrorStatus es;
    217. AcDbHatch* pHatch = new AcDbHatch();
    218. 选择填充平面
    219. AcGeVector3d normal(0,0,1);
    220. pHatch->setNormal(normal);
    221. pHatch->setElevation(0);
    222. 设置关联性
    223. pHatch->setAssociative(true);
    224. 设置填充图案
    225. pHatch->setPattern(AcDbHatch::kPreDefined,采用T(/*"SOLID"*/"ANSI31"));
    226. 设置填充角度
    227. pHatch->setPatternAngle(45);
    228. 设置填充边界
    229. es=pHatch->appendLoop(AcDbHatch::kExternal,objIds);
    230. 显示填充对象
    231. es=pHatch->evaluateHatch();
    232. LoadEntity(pHatch);
    233. }
    234. 交互函数练习==================
    235. static void TESTinputcmd(){
    236. CString outStr;
    237. //acedGetReal
    238. /*ads采用real realNum;
    239. acedGetReal(采用T("输入一个实数"),&realNum);
    240. outStr.Format(采用T("%lf"),realNum);
    241. acutPrintf(outStr);*/
    242. //acedGetInt
    243. /*int iNum;
    244. acedGetInt(采用T("输入一个整数"),&iNum);
    245. outStr.Format(采用T("%d"),iNum);
    246. acutPrintf(outStr);*/
    247. //acedGetString
    248.    /*TCHAR str[256];
    249. acedGetString(0,采用T("输入一个字符串"),str);
    250. acutPrintf(str);*/
    251. //acedGetKword
    252. /* TCHAR kw[256];
    253. acedGetKword(采用T("输入一个关键字"),kw);
    254. acutPrintf(kw);*/
    255. //acedGetPoint
    256. /* ads采用point pt;
    257. acedGetPoint(NULL,采用T("输入一个点"),pt);
    258. outStr.Format(采用T("x:%f,y:%f"),pt[X],pt[Y]);
    259. acutPrintf(outStr);*/
    260. //acedGetCorner(要与ads采用point联合使用,完成画矩形)
    261. /*ads采用point ptCorner;
    262. acedGetCorner(pt,采用T("输入对角点"),ptCorner);
    263. outStr.Format(采用T("x:%f,y:%f"),ptCorner[X],ptCorner[Y]);
    264. acutPrintf(outStr);*/
    265. //acedGetDist(和ads采用point结合使用,实现画线)
    266. /*ads采用real ptReal;
    267. acedGetDist(pt,采用T("输入目标值"),&ptReal);
    268. outStr.Format(采用T("%lf"),ptReal);
    269. acutPrintf(outStr);*/
    270. //acedGetAngle(和ads采用point结合使用,实现画线)
    271. /* ads采用real agReal;
    272. acedGetAngle(pt,采用T("输入一个角度"),&agReal);
    273. outStr.Format(采用T("%lf"),agReal);
    274. acutPrintf(outStr);*/
    275. }
    276. //获得一层的所有对象,变色===============
    277. static void TESTgetlayerobjcmd(){
    278. AcDbLayerTable *pLayerTbl;
    279. acdbHostApplicationServices()->workingDatabase()->getSymbolTable(
    280. pLayerTbl,AcDb::kForRead);
    281. if(!pLayerTbl->has(采用T("测试"))){
    282. acutPrintf(采用T("\n当前图形未包含'测试'图层"));
    283. pLayerTbl->close();
    284. return;
    285. }
    286. AcDbObjectId layerId;
    287. pLayerTbl->getAt(采用T("测试"),layerId);
    288. pLayerTbl->close();
    289. 获得当前数据库的块表
    290. AcDbBlockTable* pBlkTbl;
    291. acdbHostApplicationServices()->workingDatabase()->getBlockTable(
    292. pBlkTbl,AcDb::kForRead);
    293. 获得模型空间的块表记录
    294. AcDbBlockTableRecord* pBlkTblRcd;
    295. pBlkTbl->getAt(ACDB采用MODEL采用SPACE,pBlkTblRcd,AcDb::kForRead);
    296. pBlkTbl->close();
    297. 创建块表记录遍历器
    298. AcDbBlockTableRecordIterator* pIter;
    299. pBlkTblRcd->newIterator(pIter);
    300. AcDbEntity* pEnt;
    301. for(pIter->start();!pIter->done();pIter->step()){
    302. pIter->getEntity(pEnt,AcDb::kForWrite);
    303. if(pEnt->layerId() == layerId){
    304. /*AcDbLine* pLine = AcDbLine::cast(pEnt);
    305. if(pLine != NULL){*/
    306. pEnt->setColorIndex(1);
    307. //}
    308. }
    309. pEnt->close();
    310. }
    311. delete pIter;
    312. pBlkTblRcd->close();
    313. }
    复制代码

     

     

     

     

    OBJECT ARX 绘制常用图形 总结
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-11-1 10:24 , Processed in 0.151040 second(s), 26 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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