forked from Timelessww/DotNetARX2012
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDimTools.cs
More file actions
288 lines (285 loc) · 10.1 KB
/
Copy pathDimTools.cs
File metadata and controls
288 lines (285 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
namespace DotNetARX
{
/// <summary>
/// 与公差标注有关的特殊格式代码
/// </summary>
public struct DimFormatCode
{
/// <summary>
/// 倾斜度(∠)
/// </summary>
public static readonly string Angular=@"{\Fgdt;" + "a}";
/// <summary>
/// 垂直度(⊥)
/// </summary>
public static readonly string VerticalLine=@"{\Fgdt;" + "b}";
/// <summary>
/// 平面度(◇)
/// </summary>
public static readonly string Flatness=@"{\Fgdt;" + "c}";
/// <summary>
/// 面轮廓度(封闭的半圆)
/// </summary>
public static readonly string HalfCircleClosed=@"{\Fgdt;" + "d}";
/// <summary>
/// 圆度(○)
/// </summary>
public static readonly string SingleCircle=@"{\Fgdt;" + "e}";
/// <summary>
/// 平行度(∥)
/// </summary>
public static readonly string Parallel=@"{\Fgdt;" + "f}";
/// <summary>
/// 圆柱度
/// </summary>
public static readonly string Cylindricity=@"{\Fgdt;" + "g}";
/// <summary>
/// 圆跳动度(↗)
/// </summary>
public static readonly string CircularRunout=@"{\Fgdt;" + "h}";
/// <summary>
/// 对称度
/// </summary>
public static readonly string SymmetrySymbol=@"{\Fgdt;" + "i}";
/// <summary>
/// 位置度(⊕)
/// </summary>
public static readonly string Position=@"{\Fgdt;" + "j}";
/// <summary>
/// 线轮廓度(⌒)
/// </summary>
public static readonly string HalfCircle=@"{\Fgdt;" + "k}";
/// <summary>
/// 最小实体要求(带圆圈的L)
/// </summary>
public static readonly string CircleL=@"{\Fgdt;" + "l}";
/// <summary>
/// 最大实体要求(带圆圈的M)
/// </summary>
public static readonly string CircleM=@"{\Fgdt;" + "m}";
/// <summary>
/// 公差直径(φ)
/// </summary>
public static readonly string Diameter=@"{\Fgdt;" + "n}";
/// <summary>
/// 正方形(□)
/// </summary>
public static readonly string Square=@"{\Fgdt;" + "o}";
/// <summary>
/// 延伸公差带(带圆圈的P)
/// </summary>
public static readonly string CircleP=@"{\Fgdt;" + "p}";
/// <summary>
/// 中心线(C和L重叠)
/// </summary>
public static readonly string CenterLine=@"{\Fgdt;" + "q}";
/// <summary>
/// 同轴度(◎)
/// </summary>
public static readonly string TwoCircles=@"{\Fgdt;" + "r}";
/// <summary>
/// 不考虑特征尺寸(带圆圈的S)
/// </summary>
public static readonly string CircleS=@"{\Fgdt;" + "s}";
/// <summary>
/// 全跳动度(符号为两带箭头的斜线)
/// </summary>
public static readonly string TotalRunout=@"{\Fgdt;" + "t}";
/// <summary>
/// 直线度(―)
/// </summary>
public static readonly string Line=@"{\Fgdt;" + "u}";
/// <summary>
/// 机械制图中的柱形沉孔和锪平面孔
/// </summary>
public static readonly string CounterBore=@"{\Fgdt;" + "v}";
/// <summary>
/// 机械制图中的埋头孔(∨)
/// </summary>
public static readonly string CounterSink=@"{\Fgdt;" + "w}";
/// <summary>
/// 机械制图中的沉孔深度
/// </summary>
public static readonly string Depth=@"{\Fgdt;" + "x}";
/// <summary>
/// 锥形接续器符号
/// </summary>
public static readonly string ConicalTaper=@"{\Fgdt;" + "y}";
/// <summary>
/// 机械制图中的锥度(⊿)
/// </summary>
public static readonly string Slope=@"{\Fgdt;" + "z}";
}
/// <summary>
/// 标注中的箭头符号
/// </summary>
public struct DimArrowBlock
{
/// <summary>
/// 实心闭合
/// </summary>
public static readonly string ClosedFilled="";
/// <summary>
/// 点
/// </summary>
public static readonly string Dot="_DOT";
/// <summary>
/// 小点
/// </summary>
public static readonly string DotSmall="_DOTSMALL";
/// <summary>
/// 空心点
/// </summary>
public static readonly string DotBlank="_DOTBLANK";
/// <summary>
/// 原点标记
/// </summary>
public static readonly string Origin="_ORIGIN";
/// <summary>
/// 原点标记2
/// </summary>
public static readonly string Origin2="_ORIGIN2";
/// <summary>
/// 打开
/// </summary>
public static readonly string Open="_OPEN";
/// <summary>
/// 直角
/// </summary>
public static readonly string RightAngle="_OPEN90";
/// <summary>
/// 30度角
/// </summary>
public static readonly string Angle30="_OPEN30";
/// <summary>
/// 闭合
/// </summary>
public static readonly string Closed="_CLOSED";
/// <summary>
/// 空心小点
/// </summary>
public static readonly string DotSmallBlank="_SMALL";
/// <summary>
/// 无
/// </summary>
public static readonly string None="_NONE";
/// <summary>
/// 倾斜
/// </summary>
public static readonly string Oblique="_OBLIQUE";
/// <summary>
/// 实心框
/// </summary>
public static readonly string BoxFilled="_BOXFILLED";
/// <summary>
/// 框
/// </summary>
public static readonly string Box="_BOXBLANK";
/// <summary>
/// 空心闭合
/// </summary>
public static readonly string ClosedBlank="_CLOSEDBLANK";
/// <summary>
/// 实心基准三角形
/// </summary>
public static readonly string TriangleFilled="_DATUMFILLED";
/// <summary>
/// 基准三角形
/// </summary>
public static readonly string Triangle="_DATUMBLANK";
/// <summary>
/// 积分
/// </summary>
public static readonly string Integral="_INTEGRAL";
/// <summary>
/// 建筑标记
/// </summary>
public static readonly string ArchitecturalTick="_ARCHTICK";
}
/// <summary>
/// AutoCAD自带的用于多重引线注释块的名称
/// </summary>
public struct LeaderBlockContent
{
/// <summary>
/// 详细信息标注
/// </summary>
public static readonly string Detail="_DetailCallout";
/// <summary>
/// 方框(□)
/// </summary>
public static readonly string Box="_TagBox";
/// <summary>
/// 圆(○)
/// </summary>
public static readonly string Circle="_TagCircle";
/// <summary>
/// 正六边形
/// </summary>
public static readonly string Hexagon="_TagHexagon";
/// <summary>
/// 槽
/// </summary>
public static readonly string Slot="_TagSlot";
/// <summary>
/// 三角形(△)
/// </summary>
public static readonly string Triangle="_TagTriangle";
}
/// <summary>
/// 标注操作类(含引线、形位公差)
/// </summary>
public static class DimTools
{
#region 标注系统变量
/// <summary>
/// 当前尺寸线箭头符号
/// </summary>
public static string ArrowBlock
{
//获取DIMBLK系统变量值,它表示尺寸线末端显示的箭头块
get { return Application.GetSystemVariable("DIMBLK").ToString(); }
set
{
//设置DIMBLK系统变量值
Application.SetSystemVariable("DIMBLK", value);
}
}
#endregion
/// <summary>
/// 获取与名称对应的箭头块的ObjectId
/// </summary>
/// <param name="db">数据库对象</param>
/// <param name="arrowName">箭头名</param>
/// <returns>返回指定箭头块的ObjectId</returns>
public static ObjectId GetArrowObjectId(this Database db, string arrowName)
{
ObjectId arrId=ObjectId.Null;//存储箭头符号的ObjectId
using (Transaction trans=db.TransactionManager.StartTransaction())
{
BlockTable bt=(BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
//如果图形中存在指定名称的箭头块,则获取其ObjectId
if (bt.Has(arrowName)) arrId = bt[arrowName];
trans.Commit();
}
return arrId;//返回箭头块的ObjectId
}
/// <summary>
/// 设置形位公差值
/// </summary>
/// <param name="frame">形位公差特征控制框对象</param>
/// <param name="geometricSym">几何特征符号,表示公差的几何特征,例如位置、轮廓、形状、方向或跳动</param>
/// <param name="torlerance">公差值</param>
/// <param name="firstDatum">第一级基准要素</param>
/// <param name="secondDatum">第二级基准要素</param>
/// <param name="thirdDatum">第三级基准要素</param>
public static void CreateTolerance(this FeatureControlFrame frame, string geometricSym, string torlerance, string firstDatum, string secondDatum, string thirdDatum)
{
if (frame == null) return;//特征控制框对象必须已定义,否则返回
//设置形位公差值,各组成部分用竖线(%%v)分隔
frame.Text = geometricSym + "%%v" + torlerance + "%%v" + firstDatum + "%%v" + secondDatum + "%%v" + thirdDatum;
}
}
}