找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 193|回复: 2

ObjectARX2015 + vs2012 创建各种尺寸标注

[复制链接]

1

主题

0

回帖

35

积分

管理员

积分
35
发表于 2024-3-16 09:19:46 | 显示全部楼层 |阅读模式
  1. // 引入必要的头文件
  2. #include "dbdimvars.h"
  3. #include "dbdimdata.h"
  4. #include "dbdimline.h"
  5. #include "dbdimrotated.h"
  6. #include "dbdimrnd.h"
  7. #include "dbobjptr.h"
  8. #include "dbents.h"
  9. // 假设已获得两个点,代表标注的起点和终点
  10. AcGePoint3d startPt, endPt;
  11. // 获取当前工作数据库
  12. AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
  13. // 锁定数据库以防止并发修改
  14. AcDbVoidPtrArray objectsToLock;
  15. objectsToLock.append(pDb);
  16. pDb->lockObjects(objectsToLock);
  17. try {
  18.     // 创建一个新的尺寸标注对象
  19.     AcDbDimLinear* pDim = new AcDbDimLinear();
  20.     // 设置尺寸线的起点和终点
  21.     pDim->setDefpoint(startPt, AcDbDim::kFirstExtensionPoint);
  22.     pDim->setDefpoint(endPt, AcDbDim::kSecondExtensionPoint);
  23.     // 关联到实体,例如一条直线
  24.     AcDbLine* pLine = new AcDbLine(startPt, endPt);
  25.     pDim->associateEntity(pLine->objectId());
  26.     // 设置标注的其他属性,如标注样式、文本位置、角度等
  27.     pDim->setTextStyle(/* 标注样式名 */);
  28.     pDim->setRotation(/* 标注旋转角度 */);
  29.     pDim->setTextPosition(AcDbDim::kAboveDimLineCenterAligned);
  30.     // 插入到当前图形空间
  31.     AcDbBlockTableRecord* pBlockRec = NULL;
  32.     pDb->getActiveSpaceId().openObject(pBlockRec, AcDb::kForWrite);
  33.     Acad::ErrorStatus es = pBlockRec->appendAcDbEntity(pDim);
  34.     if (es != Acad::eOk) {
  35.         // 处理错误
  36.     }
  37.     // 提交事务
  38.     pDb->databaseDefaults().dimstyle(OBJECTID采用OF采用DIMSTYLE采用TO采用USE);
  39.     pDim->setDatabaseDefaults();
  40.     pDim->close();
  41.     pLine->erase(true);
  42.     pBlockRec->close();
  43. } catch (...) {
  44.     // 清理异常,撤销操作
  45. }
  46. // 解锁数据库
  47. pDb->unlockObjects(objectsToLock);
  48. // 提交事务(确保在命令结束前提交)
  49. Acad::ErrorStatus es = acdbCurTransaction()->commit();
  50. if (es != Acad::eOk) {
  51.     // 处理提交失败
  52. }
  53. // 释放资源
  54. acdbHostApplicationServices()->workingDatabase()->release(pDb);
复制代码

1

主题

0

回帖

35

积分

管理员

积分
35
 楼主| 发表于 2024-3-16 09:24:35 | 显示全部楼层
  1. 线性对齐标注 (AcDbAlignedDimension):
  2. Cpp
  3. // 假设有两条线的端点定义了对齐方向
  4. AcGePoint3d basePt, definingLineStart, definingLineEnd;
  5. AcDbAlignedDimension *pAlignedDim = new AcDbAlignedDimension;
  6. pAlignedDim->setDefiningLine(definingLineStart, definingLineEnd); // 设置定义线
  7. pAlignedDim->setBasePoint(basePt); // 设置基准点
  8. // 然后同线性标注一样设置关联实体、标注样式、文本位置等属性
  9. // 并插入到块记录中
  10. 旋转标注 (AcDbRotatedDimension):
  11. Cpp
  12. AcGePoint3d dimLineOrigin, leaderEndPoint;
  13. double rotationAngle;
  14. AcDbRotatedDimension *pRotatedDim = new AcDbRotatedDimension;
  15. pRotatedDim->setDefpoint(dimLineOrigin); // 设置维度线原点
  16. pRotatedDim->setLeaderEndPoint(leaderEndPoint); // 设置引线端点
  17. pRotatedDim->setRotation(rotationAngle); // 设置旋转角度
  18. // 同样设置关联实体、标注样式等属性,并插入到块记录中
  19. 径向标注 (AcDbRadialDimension):
  20. Cpp
  21. AcGePoint3d centerPt, chordPt;
  22. AcDbRadialDimension *pRadialDim = new AcDbRadialDimension;
  23. pRadialDim->setCenter(centerPt); // 设置圆心点
  24. pRadialDim->setChordPoint(chordPt); // 设置弦上的点
  25. // 接着设置关联实体、标注样式等属性,并插入到块记录中
  26. 直径标注 (AcDbDiametricDimension):
  27. Cpp
  28. AcGePoint3d arcMidPt, chordPt;
  29. AcDbDiametricDimension *pDiametricDim = new AcDbDiametricDimension;
  30. pDiametricDim->setArcMidPoint(arcMidPt); // 设置圆弧中点
  31. pDiametricDim->setChordPoint(chordPt); // 设置通过圆弧的弦上的点
  32. // 同样完成其他属性设置和插入操作
  33. 两线角度标注 (AcDb2LineAngularDimension):
  34. Cpp
  35. AcGePoint3d line1Start, line1End, line2Start, line2End;
  36. AcDb2LineAngularDimension *p2LineAngDim = new AcDb2LineAngularDimension;
  37. p2LineAngDim->setLine1StartPoint(line1Start);
  38. p2LineAngDim->setLine1EndPoint(line1End);
  39. p2LineAngDim->setLine2StartPoint(line2Start);
  40. p2LineAngDim->setLine2EndPoint(line2End);
  41. // 完成后续属性设置和插入
  42. 三点角度标注 (AcDb3PointAngularDimension):
  43. Cpp
  44. AcGePoint3d pt1, pt2, pt3;
  45. AcDb3PointAngularDimension *p3PointAngDim = new AcDb3PointAngularDimension;
  46. p3PointAngDim->setPoint1(pt1);
  47. p3PointAngDim->setPoint2(pt2);
  48. p3PointAngDim->setPoint3(pt3);
  49. // 其他属性设置和插入操作
  50. 坐标标注 (AcDbOrdinateDimension):
  51. Cpp
  52. AcGePoint3d originPt, definedPt;
  53. AcDbOrdinateDimension *pOrdinateDim = new AcDbOrdinateDimension;
  54. pOrdinateDim->setOrigin(originPt); // 设置原点
  55. pOrdinateDim->setDefinedPoint(definedPt); // 设置被定义点
  56. // 指定坐标类型(X, Y 或 Z),以及其他属性设置和插入操作
复制代码

1

主题

0

回帖

35

积分

管理员

积分
35
 楼主| 发表于 2024-3-16 09:25:10 | 显示全部楼层
  1. //当前项目中注册一个命令 MyCreateDimAligned
  2.     static void MidasMyGroupMyCreateDimAligned()
  3.     {
  4.         CGeometryOper m采用geometryOper;
  5.         // 指定起始点位置
  6.         AcGePoint3d pt1(200, 160, 0);
  7.         AcGePoint3d pt2= m采用geometryOper.RelativePoint(pt1, -40, 0);
  8.         AcGePoint3d pt3 = m采用geometryOper.PolarPoint(pt2, 7 * m采用geometryOper.PI() / 6, 20);
  9.         AcGePoint3d pt4 = m采用geometryOper.RelativePoint(pt3, 6, -10);
  10.         AcGePoint3d pt5 = m采用geometryOper.RelativePoint(pt1, 0, -20);
  11.         // 绘制外轮廓线
  12.         CCreateEnt::CreateLine(pt1, pt2);
  13.         CCreateEnt::CreateLine(pt2, pt3);
  14.         CCreateEnt::CreateLine(pt3, pt4);
  15.         CCreateEnt::CreateLine(pt4, pt5);
  16.         CCreateEnt::CreateLine(pt5, pt1);
  17.         // 绘制圆形
  18.         AcGePoint3d ptCenter1, ptCenter2;
  19.         ptCenter1 = m采用geometryOper.RelativePoint(pt3, 16, 0);
  20.         ptCenter2 = m采用geometryOper.RelativePoint(ptCenter1, 25, 0);
  21.         CCreateEnt::CreateCircle(ptCenter1, 3);
  22.         CCreateEnt::CreateCircle(ptCenter2, 4);
  23.         AcGePoint3d ptTemp1, ptTemp2;
  24.         // 水平标注
  25.         ptTemp1 = m采用geometryOper.RelativePoint(pt1, -20, 3);
  26.         CCreateEnt::CreateDimRotated(pt1, pt2, ptTemp1, 0);
  27.         // 垂直标注
  28.         ptTemp1 = m采用geometryOper.RelativePoint(pt1, 4, 10);
  29.         CCreateEnt::CreateDimRotated(pt1, pt5, ptTemp1,
  30.             m采用geometryOper.PI() / 2);
  31.         // 转角标注
  32.         ptTemp1 = m采用geometryOper.RelativePoint(pt3, -3, -6);
  33.         CCreateEnt::CreateDimRotated(pt3, pt4, ptTemp1, 7 * m采用geometryOper.PI() / 4);
  34.         // 对齐标注
  35.         ptTemp1 = m采用geometryOper.RelativePoint(pt2, -3, 4);
  36.         CCreateEnt::CreateDimAligned(pt2, pt3, ptTemp1, AcGeVector3d(4, 10, 0), 采用T("new position"));
  37.         // 角度标注
  38.         ptTemp1 = m采用geometryOper.RelativePoint(pt5, -5, 5);
  39.         CCreateEnt::CreateDim3PtAngular(pt5, pt1, pt4, ptTemp1);
  40.         // 半径标注
  41.         ptTemp1 = m采用geometryOper.PolarPoint(ptCenter1, m采用geometryOper.PI() / 4, 3);
  42.         CCreateEnt::CreateDimRadial(ptCenter1, ptTemp1, -3);
  43.         // 直径标注
  44.         ptTemp1 = m采用geometryOper.PolarPoint(ptCenter2,
  45.             m采用geometryOper.PI() / 4, 4);
  46.         ptTemp2 = m采用geometryOper.PolarPoint(ptCenter2,
  47.             m采用geometryOper.PI() / 4, -4);
  48.         CCreateEnt::CreateDimDiametric(ptTemp1, ptTemp2, 0);
  49.         // 坐标标注
  50.         CCreateEnt::CreateDimOrdinate(ptCenter2, AcGeVector3d(0, -10, 0),
  51.             AcGeVector3d(10, 0, 0));
  52.     }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-1-1 17:21 , Processed in 0.128896 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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