录制_2021_07_31_12_22_55_204.gif

    1. //============================================================
    2. #region 标注方法
    3. /// <summary>
    4. /// 创建转角标注
    5. /// </summary>
    6. /// <param name="pt1">标注起始点</param>
    7. /// <param name="pt2">标注结束点</param>
    8. /// <param name="txtpt">文字放置点</param>
    9. /// <param name="txt">标注内容</param>
    10. /// <param name="IsH">是否横向</param>
    11. /// <param name="scal">标注全局比例</param>
    12. /// <param name="lfac">标注线性比例</param>
    13. /// <param name="dec">标注精度</param>
    14. /// <returns>图元ObjectId</returns>
    15. public static ObjectId RotatedDim(Point3d pt1, Point3d pt2, Point3d txtpt, string txt, bool IsH, double scal = 1, double lfac = 1, int dec = 0)
    16. {
    17. RotatedDimension dim = new RotatedDimension
    18. {
    19. XLine1Point = pt1,
    20. XLine2Point = pt2,
    21. DimLinePoint = txtpt,
    22. TextPosition = txtpt,
    23. DimensionText = txt,
    24. Dimdec = dec,
    25. Dimscale = scal,
    26. Dimlfac = lfac
    27. };
    28. dim.Rotation = IsH ? 0 : Math.PI * 0.5;
    29. return db.AddEntityToModelSpace(dim);
    30. }
    31. /// <summary>
    32. /// 创建转角标注
    33. /// </summary>
    34. /// <param name="pt1">标注起始点</param>
    35. /// <param name="pt2">标注结束点</param>
    36. /// <param name="txtpt">文字放置点</param>
    37. /// <param name="txt">标注内容</param>
    38. /// <param name="IsH">是否横向</param>
    39. /// <param name="scal">标注全局比例</param>
    40. /// <param name="lfac">标注线性比例</param>
    41. /// <param name="dec">标注精度</param>
    42. /// <returns>图元ObjectId</returns>
    43. public static ObjectId RotatedDim(Point2d pt1, Point2d pt2, Point2d txtpt, string txt, bool IsH, double scal = 1, double lfac = 1, int dec = 0)
    44. {
    45. return RotatedDim(new Point3d(pt1.X, pt1.Y, 0), new Point3d(pt2.X, pt2.Y, 0), new Point3d(txtpt.X, txtpt.Y, 0), txt, IsH, scal, lfac, dec);
    46. }
    47. /// <summary>
    48. /// 创建圆弧半径标注
    49. /// </summary>
    50. /// <param name="center">圆弧圆心</param>
    51. /// <param name="startang">圆弧起始角度</param>
    52. /// <param name="endang">圆弧终点角度</param>
    53. /// <param name="cpt">标注弦点</param>
    54. /// <param name="txtpt">标注文字放置点</param>
    55. /// <param name="dimstr">标注内容</param>
    56. /// <param name="scal">标注全局比例</param>
    57. /// <param name="lfac">标注线性比例</param>
    58. /// <returns>图元ObjectId</returns>
    59. public static ObjectId ArcRadialDim(Point3d center, double startang, double endang, Point3d cpt, Point3d txtpt, string dimstr, double scal, double lfac)
    60. {
    61. RadialDimension rdim = new RadialDimension
    62. {
    63. Center = center,
    64. ChordPoint = cpt,
    65. DimensionText = dimstr,
    66. UsingDefaultTextPosition = true,
    67. LeaderLength = 5,
    68. Dimscale = scal,
    69. Dimlfac = lfac,
    70. TextPosition = txtpt
    71. };
    72. ResultBuffer resBuf = new ResultBuffer
    73. {
    74. new TypedValue((int)DxfCode.ExtendedDataRegAppName, "ACAD_DSTYLE_DIMRADIAL_EXTENSION"),
    75. new TypedValue((int)DxfCode.ExtendedDataInteger16, 387),
    76. new TypedValue((int)DxfCode.ExtendedDataInteger16, 1),
    77. new TypedValue((int)DxfCode.ExtendedDataInteger16, 388),
    78. new TypedValue((int)DxfCode.ExtendedDataReal, startang),//圆弧的开始角度
    79. new TypedValue((int)DxfCode.ExtendedDataInteger16, 390),
    80. new TypedValue((int)DxfCode.ExtendedDataReal, endang)//圆弧的结束角度
    81. };
    82. rdim.XData = resBuf;
    83. return db.AddEntityToModelSpace(rdim);
    84. }
    85. /// <summary>
    86. /// 创建圆弧半径标注
    87. /// </summary>
    88. /// <param name="center">圆弧圆心</param>
    89. /// <param name="startang">圆弧起始角度</param>
    90. /// <param name="endang">圆弧终点角度</param>
    91. /// <param name="cpt">标注弦点</param>
    92. /// <param name="txtpt">标注文字放置点</param>
    93. /// <param name="dimstr">标注内容</param>
    94. /// <param name="scal">标注全局比例</param>
    95. /// <param name="lfac">标注线性比例</param>
    96. /// <returns>图元ObjectId</returns>
    97. public static ObjectId ArcRadialDim(Point2d center, double startang, double endang, Point2d cpt, Point2d txtpt, string dimstr, double scal, double lfac)
    98. {
    99. return ArcRadialDim(new Point3d(center.X, center.Y, 0), startang, endang, new Point3d(cpt.X, cpt.Y, 0), new Point3d(txtpt.X, txtpt.Y, 0), dimstr, scal, lfac);
    100. }
    101. /// <summary>
    102. /// 创建直径标注
    103. /// </summary>
    104. /// <param name="cpt">第一标注点</param>
    105. /// <param name="fcpt">第二标注点</param>
    106. /// <param name="txtpt">文字放置点</param>
    107. /// <param name="scal">标注全局比例</param>
    108. /// <param name="lfac">标注线性比例</param>
    109. /// <param name="dec">标注精度</param>
    110. /// <returns>图元ObjectId</returns>
    111. public static ObjectId DiametricDim(Point3d cpt, Point3d fcpt, Point3d txtpt, string dimstr = "<>", double scal = 1, double lfac = 1, int dec = 0)
    112. {
    113. DiametricDimension dim = new DiametricDimension
    114. {
    115. ChordPoint = cpt,
    116. FarChordPoint = fcpt,
    117. TextPosition = txtpt,
    118. DimensionText = dimstr,
    119. Dimdec = dec,
    120. Dimscale = scal,
    121. Dimlfac = lfac
    122. };
    123. return db.AddEntityToModelSpace(dim);
    124. }
    125. /// <summary>
    126. /// 创建直径标注
    127. /// </summary>
    128. /// <param name="cpt">第一标注点</param>
    129. /// <param name="fcpt">第二标注点</param>
    130. /// <param name="txtpt">文字放置点</param>
    131. /// <param name="scal">标注全局比例</param>
    132. /// <param name="lfac">标注线性比例</param>
    133. /// <param name="dec">标注精度</param>
    134. /// <returns>图元ObjectId</returns>
    135. public static ObjectId DiametricDim(Point2d cpt, Point2d fcpt, Point2d txtpt, string dimstr = "<>", double scal = 1, double lfac = 1, int dec = 0)
    136. {
    137. return DiametricDim(new Point3d(cpt.X, cpt.Y, 0), new Point3d(fcpt.X, fcpt.Y, 0), new Point3d(txtpt.X, txtpt.Y, 0), dimstr, scal, lfac, dec);
    138. }
    139. /// <summary>
    140. /// 创建直线角度标注
    141. /// </summary>
    142. /// <param name="pt1s">起始角度直线起始点</param>
    143. /// <param name="pt1e">起始角度直线终止点</param>
    144. /// <param name="pt2s">终止角度直线起始点</param>
    145. /// <param name="pt2e">终止角度直线终止点</param>
    146. /// <param name="arcpt">圆弧位置点</param>
    147. /// <param name="scal">标注全局比例</param>
    148. /// <param name="lfac">标注线性比例</param>
    149. /// <param name="dec">标注精度</param>
    150. /// <returns>图元ObjectId</returns>
    151. public static ObjectId AngularDim(Point3d pt1s, Point3d pt1e, Point3d pt2s, Point3d pt2e, Point3d arcpt, double scal = 1, double lfac = 1, int dec = 0)
    152. {
    153. LineAngularDimension2 dim = new LineAngularDimension2
    154. {
    155. XLine1Start = pt1s,
    156. XLine1End = pt1e,
    157. XLine2Start = pt2s,
    158. XLine2End = pt2e,
    159. ArcPoint = arcpt,
    160. Dimdec = dec,
    161. Dimadec = dec,
    162. Dimscale = scal,
    163. Dimlfac = lfac
    164. };
    165. return db.AddEntityToModelSpace(dim);
    166. }
    167. /// <summary>
    168. /// 创建直线角度标注
    169. /// </summary>
    170. /// <param name="pt1s">起始角度直线起始点</param>
    171. /// <param name="pt1e">起始角度直线终止点</param>
    172. /// <param name="pt2s">终止角度直线起始点</param>
    173. /// <param name="pt2e">终止角度直线终止点</param>
    174. /// <param name="arcpt">圆弧位置点</param>
    175. /// <param name="scal">标注全局比例</param>
    176. /// <param name="lfac">标注线性比例</param>
    177. /// <param name="dec">标注精度</param>
    178. /// <returns>图元ObjectId</returns>
    179. public static ObjectId AngularDim(Point2d pt1s, Point2d pt1e, Point2d pt2s, Point2d pt2e, Point2d arcpt, double scal = 1, double lfac = 1, int dec = 0)
    180. {
    181. return AngularDim(new Point3d(pt1s.X, pt1s.Y, 0), new Point3d(pt1e.X, pt1e.Y, 0), new Point3d(pt2s.X, pt2s.Y, 0), new Point3d(pt2e.X, pt2e.Y, 0), new Point3d(arcpt.X, arcpt.Y, 0), scal, lfac, dec);
    182. }
    183. #endregion
    184. //============================================================