天气与日历 切换到窄版

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

OBJECT ARX 移动,拷贝 旋转,镜像,缩放

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

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-5-2 22:49:29 | 显示全部楼层 |阅读模式
    1. //拷贝,移动,旋转 ,镜像,缩放
    2. 选择一个对象
    3. static BOOL SelObj(ads采用point& pt,AcDbObjectId& objId){
    4. ads采用name en;
    5. if(acedEntSel(采用T("\n选择对象"),en,pt) != RTNORM){
    6. return false;
    7. }
    8. Acad::ErrorStatus es = acdbGetObjectId(objId,en);
    9. return es == Acad::ErrorStatus::eOk ? true : false;
    10. }
    11. //选择一个点
    12. static BOOL SelPoint(ads采用point& ptEnd){
    13. if(acedGetPoint(NULL,采用T("\n选择一个点"),ptEnd) != RTNORM){
    14. return false;
    15. }
    16. return true;
    17. }
    18. 拷贝函数测试
    19. static void TESTcopycmd(){
    20. AcDbObjectId objId;
    21. ads采用point ptStart;
    22. ads采用point ptEnd;
    23. if(!SelObj(ptStart,objId)){
    24. acutPrintf(采用T("选择对象失败"));
    25. };
    26. if(!SelPoint(ptEnd)){
    27. acutPrintf(采用T("选择点失败"));
    28. }
    29. CopyTo(objId,ptStart,ptEnd);
    30. }
    31. 拷贝函数
    32. static BOOL CopyTo(AcDbObjectId entId,const ads采用point& ptFrom,
    33. const ads采用point& ptTo){
    34. AcDbEntity* pEnt = NULL;
    35. if(acdbOpenObject(pEnt,entId,AcDb::kForRead) != Acad::eOk){
    36. return FALSE;
    37. }
    38. AcDbEntity* pCopyEnt = AcDbEntity::cast(pEnt->clone());
    39. AcDbObjectId copyEntId;
    40. if(pCopyEnt){
    41. copyEntId = LoadEntity(pCopyEnt);
    42. }
    43. Move(copyEntId,ptFrom,ptTo);
    44. }
    45. 移动函数测试============
    46. static void TESTmovecmd(){
    47. AcDbObjectId objId;
    48. ads采用point ptStart;
    49. ads采用point ptEnd;
    50. if(!SelObj(ptStart,objId)){
    51. acutPrintf(采用T("选择对象失败"));
    52. };
    53. if(!SelPoint(ptEnd)){
    54. acutPrintf(采用T("选择点失败"));
    55. }
    56. Move(objId,ptStart,ptEnd);
    57. }
    58. 移动函数
    59. static Acad::ErrorStatus Move(AcDbObjectId entId,const ads采用point& ptFrom,const ads采用point& ptTo){
    60. AcGeVector3d vec(ptTo[X] - ptFrom[X],ptTo[Y] - ptFrom[Y],
    61. ptTo[Z] - ptFrom[Z]);
    62. AcGeMatrix3d mat;
    63. mat.setToTranslation(vec);
    64. AcDbEntity* pEnt = NULL;
    65. Acad::ErrorStatus es = acdbOpenObject(pEnt,entId,AcDb::kForWrite);
    66. if(es!=Acad::eOk){
    67. return es;
    68. }
    69. es=pEnt->transformBy(mat);
    70. pEnt->close();
    71. }
    72. 缩放
    73. static void TESTsccmd()
    74. {
    75. ads采用name name;
    76. ads采用point ptEnt;
    77. AcDbObjectId id;
    78. if(acedEntSel(采用T("选择要扩大的实体"),name,ptEnt) != RTNORM)
    79. {
    80. acutPrintf(采用T("\nno obj select"));
    81. return;
    82. }
    83. if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
    84. {
    85. return;
    86. }
    87. AcDbEntity* pEnt;
    88. if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
    89. {
    90. acutPrintf(采用T("\n打开实体失败"));
    91. return;
    92. }
    93. ads采用real num;
    94. if(acedGetReal(采用T("\n输入扩展倍数"),&num) != RTNORM)
    95. {
    96. pEnt->close();
    97. return;
    98. }
    99. ads采用point pt;
    100. if(acedGetPoint(NULL,采用T("\n选择基点"),pt) != RTNORM)
    101. {
    102. pEnt->close();
    103. return;
    104. }
    105. AcGePoint3d pt3d = asPnt3d(pt);
    106. AcGeMatrix3d mat;
    107. mat.setToScaling(num,pt3d);
    108. pEnt->transformBy(mat);
    109. pEnt->close();
    110. }
    111. 旋转
    112. static void TESTrtcmd()
    113. {
    114. ads采用name name;
    115. ads采用point ptEnt;
    116. AcDbObjectId id;
    117. if(acedEntSel(采用T("选择要旋转的实体"),name,ptEnt) != RTNORM)
    118. {
    119. acutPrintf(采用T("\nno obj select"));
    120. return;
    121. }
    122. if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
    123. {
    124. return;
    125. }
    126. AcDbEntity* pEnt;
    127. if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
    128. {
    129. acutPrintf(采用T("\n打开实体失败"));
    130. return;
    131. }
    132. ads采用point ptBase;
    133. if(acedGetPoint(NULL,采用T("\n选择旋转的基点"),ptBase) != RTNORM)
    134. {
    135. pEnt->close();如果不及时关闭,会导致内存泄漏
    136. return;
    137. }
    138. ads采用real angle;
    139. if(acedGetAngle(ptBase,采用T("\n输入旋转角度"),&angle) != RTNORM)
    140. {
    141. pEnt->close();
    142. return;
    143. }
    144. AcDbCurve* pCurve;
    145. pCurve = (AcDbCurve*)pEnt;
    146. AcGePoint3d ptCenter;
    147. pCurve->getStartPoint(ptCenter);
    148. AcGeMatrix3d mat;
    149. acutPrintf(采用T("angle is %.2f"),angle);
    150. mat.setToRotation(angle,AcGeVector3d::kZAxis,ptCenter);
    151. //mat.rotation(angle,AcGeVector2d::kXAxis,ptCenter);
    152. pEnt->transformBy(mat);
    153. pEnt->close();
    154. }
    155. 镜像
    156. static void TESTmrcmd()
    157. {
    158. ads采用name name;
    159. ads采用point ptEnt;
    160. AcDbObjectId id;
    161. if(acedEntSel(采用T("选择要镜像的实体"),name,ptEnt) != RTNORM)
    162. {
    163. acutPrintf(采用T("\nno obj select"));
    164. return;
    165. }
    166. if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
    167. {
    168. return;
    169. }
    170. AcDbEntity* pEnt;
    171. if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
    172. {
    173. acutPrintf(采用T("\n打开实体失败"));
    174. return;
    175. }
    176. ads采用point ptDis1;
    177. if(acedGetPoint(NULL,采用T("\n选择镜像点1"),ptDis1) !=RTNORM)
    178. {
    179. acutPrintf(采用T("\nno point select"));
    180. pEnt->close();
    181. return;
    182. }
    183. ads采用point ptDis2;
    184. if(acedGetPoint(NULL,采用T("\n选择镜像点2"),ptDis2) !=RTNORM)
    185. {
    186. acutPrintf(采用T("\nno point select"));
    187. pEnt->close();
    188. return;
    189. }
    190. AcGePoint3d ptDis3d1 = asPnt3d(ptDis1);
    191. AcGePoint3d ptDis3d2 = asPnt3d(ptDis2);
    192. AcGeLine3d line(ptDis3d1,ptDis3d2);
    193. AcGeMatrix3d mat ;
    194. mat.setToMirroring(line);
    195. acedInitGet(NULL,采用T("Y N"));
    196. CString strKW;
    197. if(acedGetKword(采用T("删除原对象?Y/N"),strKW.GetBuffer(1)) != RTNORM)
    198. {
    199. return;
    200. }
    201. strKW.ReleaseBuffer();
    202. if(strKW.CompareNoCase(采用T("N")) == 0)
    203. {
    204. AcDbEntity* pEnt2 = AcDbEntity::cast(pEnt->clone());
    205. LoadEntity(pEnt2);
    206. pEnt2->close();
    207. }
    208. pEnt->transformBy(mat);
    209. pEnt->close();
    210. }
    211. }
    复制代码

     

     

     

     

    OBJECT ARX 移动,拷贝 旋转,镜像,缩放
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-11-1 09:04 , Processed in 0.131807 second(s), 25 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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