/
tcBolt.cs
618 lines (575 loc) · 16.8 KB
/
tcBolt.cs
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using System.Collections;
using SRI=System.Runtime.InteropServices;
using Bentley.ProStructures;
using ProStructuresOE;
using Bentley.ProStructures.CadSystem;
using Bentley.ProStructures.Configuration;
using Bentley.ProStructures.Drawing;
using Bentley.ProStructures.Geometry.Data;
using Bentley.ProStructures.Geometry.Utilities;
using Bentley.ProStructures.Miscellaneous;
using Bentley.ProStructures.Property;
using Bentley.ProStructures.Entity;
using Bentley.ProStructures.Steel.Plate;
using Bentley.ProStructures.Steel.Primitive;
using Bentley.ProStructures.Steel.Bolt;
using Bentley.ProStructures.Modification.Edit;
using Bentley.ProStructures.Modification.ObjectData;
using Microsoft.VisualBasic;
using PlugInBase;
using BM=Bentley.MicroStation;
using BMW=Bentley.MicroStation.WinForms;
using BMI=Bentley.MicroStation.InteropServices;
using BCOM=Bentley.Interop.MicroStationDGN;
namespace GSFBolt
{
public class TcBolt
{
public double Diameter;
public double Length;
public double KlemmLength;
public double LengthAdd;
public double HeadHeight;
public double HeadDiameter;
public double WasherOuterDiameter;
public double WasherThickness;
public double NutKeySize;
public double NutHeight;
public int ObjectId;
public string Name;
public string Type;
public string MaterialName;
public int MaterialIndex;
public int Color;
public bool PartListFlag;
public bool ModifyFlag;
public int PartFamilyClassIndex;
public PsPoint InsertPoint;
public PsVector XAxis;
public PsVector YAxis;
public PsVector ZAxis;
public TcBolt()
{
}
public void SetParams(double TcBoltDiameter, string TcBoltType, double BoltAddLength)
{
PsUnits psUnits = new PsUnits();
Diameter = TcBoltDiameter;
LengthAdd = BoltAddLength;
if (TcBoltDiameter == 0.5D)
{
HeadHeight = 0.323D;
HeadDiameter = 1.126D;
WasherOuterDiameter = 1.063D;
WasherThickness = 0.097D;
NutKeySize = 0.875D;
NutHeight = 0.504D;
}
else if (TcBoltDiameter == 0.625D)
{
HeadHeight = 0.403D;
HeadDiameter = 1.313D;
WasherOuterDiameter = 1.313D;
WasherThickness = 0.122D;
NutKeySize = 1.062D;
NutHeight = 0.631D;
}
else if (TcBoltDiameter == 0.75D)
{
HeadHeight = 0.483D;
HeadDiameter = 1.580D;
WasherOuterDiameter = 1.468D;
WasherThickness = 0.122D;
NutKeySize = 1.250D;
NutHeight = 0.758D;
}
else if (TcBoltDiameter == 0.875D)
{
HeadHeight = 0.563D;
HeadDiameter = 1.880D;
WasherOuterDiameter = 1.750D;
WasherThickness = 0.136D;
NutKeySize = 1.438D;
NutHeight = 0.885D;
}
else if (TcBoltDiameter == 1D)
{
HeadHeight = 0.627D;
HeadDiameter = 2.158D;
WasherOuterDiameter = 2.000D;
WasherThickness = 0.136D;
NutKeySize = 1.625D;
NutHeight = 1.012D;
}
else
{
HeadHeight = 0.718D;
HeadDiameter = 2.375D;
WasherOuterDiameter = 2.250D;
WasherThickness = 0.177D;
NutKeySize = 1.812D;
NutHeight = 1.139D;
}
if (TcBoltType == "SHOP TC A325")
{
Type = "SHOP TC Bolt";
MaterialName = "ASTM A325 Gr.81";
Color = 20;
}
else if (TcBoltType == "FIELD TC A325")
{
Type = "FIELD TC Bolt";
MaterialName = "ASTM A325 Gr.81";
Color = 7;
}
else if (TcBoltType == "SHOP TC A490")
{
Type = "SHOP TC Bolt";
MaterialName = "ASTM A490";
Color = 202;
}
else
{
Type = "FIELD TC Bolt";
MaterialName = "ASTM A490";
Color = 94;
}
}
public void SetStandardBoltParams(double StandardBoltDiameter, string StandardBoltStyle, double BoltAddLength)
{
PsUnits psUnits = new PsUnits();
Diameter = StandardBoltDiameter;
LengthAdd = BoltAddLength;
if (StandardBoltDiameter == 0.5D)
{
HeadHeight = 0.323D;
HeadDiameter = 1.126D;
WasherOuterDiameter = 1.063D;
WasherThickness = 0.097D;
NutKeySize = 0.875D;
NutHeight = 0.504D;
}
else if (StandardBoltDiameter == 0.625D)
{
HeadHeight = 0.403D;
HeadDiameter = 1.313D;
WasherOuterDiameter = 1.313D;
WasherThickness = 0.122D;
NutKeySize = 1.062D;
NutHeight = 0.631D;
}
else if (StandardBoltDiameter == 0.75D)
{
HeadHeight = 0.483D;
HeadDiameter = 1.580D;
WasherOuterDiameter = 1.468D;
WasherThickness = 0.122D;
NutKeySize = 1.250D;
NutHeight = 0.758D;
}
else if (StandardBoltDiameter == 0.875D)
{
HeadHeight = 0.563D;
HeadDiameter = 1.880D;
WasherOuterDiameter = 1.750D;
WasherThickness = 0.136D;
NutKeySize = 1.438D;
NutHeight = 0.885D;
}
else if (StandardBoltDiameter == 1D)
{
HeadHeight = 0.627D;
HeadDiameter = 2.158D;
WasherOuterDiameter = 2.000D;
WasherThickness = 0.136D;
NutKeySize = 1.625D;
NutHeight = 1.012D;
}
else
{
HeadHeight = 0.718D;
HeadDiameter = 2.375D;
WasherOuterDiameter = 2.250D;
WasherThickness = 0.177D;
NutKeySize = 1.812D;
NutHeight = 1.139D;
}
if (StandardBoltStyle == "A325 SHOP")
{
Type = "SHOP TC Bolt";
MaterialName = "ASTM A325 Gr.81";
Color = 20;
}
else if (StandardBoltStyle == "A325 FIELD")
{
Type = "FIELD TC Bolt";
MaterialName = "ASTM A325 Gr.81";
Color = 7;
}
else if (StandardBoltStyle == "A490 SHOP")
{
Type = "SHOP TC Bolt";
MaterialName = "ASTM A490";
Color = 202;
}
else
{
Type = "FIELD TC Bolt";
MaterialName = "ASTM A490";
Color = 94;
}
}
public void CreateByTwoPoints(PsPoint StartPoint, PsPoint EndPoint)
{
PsCreatePrimitive psCylinder = new PsCreatePrimitive();
PsCreatePrimitive psHead1 = new PsCreatePrimitive();
PsCreatePrimitive psHead2 = new PsCreatePrimitive();
PsCreatePrimitive psWasher = new PsCreatePrimitive();
PsCreatePrimitive psNut = new PsCreatePrimitive();
PsPolygon psNutPolygon = new PsPolygon();
PsVector psVector1 = new PsVector();
PsVector psVector2 = new PsVector();
PsVector psVector3 = new PsVector();
PsVector psVector = new PsVector();
psVector1.SetFromPoints(StartPoint, EndPoint);
psVector2 = psVector.GetPerpendicularVector(psVector1);
psVector3.SetFromCrossProduct(psVector1, psVector2);
InsertPoint = StartPoint;
KlemmLength = psVector1.Length;
psVector1.Normalize();
psVector2.Normalize();
psVector3.Normalize();
ZAxis = psVector1;
XAxis = psVector2;
YAxis = psVector3;
psCylinder.SetXYPlane(XAxis, YAxis);
psCylinder.SetInsertPoint(InsertPoint);
Length = Math.Round((KlemmLength + WasherThickness + NutHeight + LengthAdd + 0.375D)*4, MidpointRounding.ToEven)/4;
psCylinder.CreateCylinder(Diameter/2, Length);
// Head
PsVector XAxisNegative = new PsVector();
XAxisNegative = XAxis.Clone();
XAxisNegative.Invert();
psHead1.SetXYPlane(XAxisNegative,YAxis);
psHead1.SetInsertPoint(InsertPoint);
psHead1.CreateCylinder(HeadDiameter/2, HeadHeight/4);
PsPoint head2InsertPoint = new PsPoint();
head2InsertPoint = InsertPoint.Clone();
head2InsertPoint.AddScaled(ZAxis, -1*HeadHeight/4);
psHead2.SetXYPlane(XAxisNegative, YAxis);
psHead2.SetInsertPoint(head2InsertPoint);
psHead2.CreateCone(HeadDiameter/2, HeadDiameter/6, 0.75*HeadHeight);
// Washer
psWasher.SetXYPlane(XAxis, YAxis);
psWasher.SetInsertPoint(EndPoint);
psWasher.CreateCylinder(WasherOuterDiameter/2, WasherThickness);
// Nut
PsPoint nutInsertPoint = new PsPoint();
nutInsertPoint = EndPoint.Clone();
nutInsertPoint.AddScaled(ZAxis, WasherThickness);
psNutPolygon.createPolygon(6, NutKeySize/2, false);
psNut.SetXYPlane(XAxis, YAxis);
psNut.SetPolygon(psNutPolygon);
psNut.SetInsertPoint(nutInsertPoint);
psNut.CreateExtrusion(NutHeight, 0D, 0D);
// Unite all
int cylinderId = psCylinder.ObjectId;
int head1Id = psHead1.ObjectId;
int head2Id = psHead2.ObjectId;
int washerId = psWasher.ObjectId;
int nutId = psNut.ObjectId;
int[] ids = {head1Id, head2Id, washerId, nutId};
PsCutObjects psUniteObjects = new PsCutObjects();
psUniteObjects.SetObjectId(cylinderId);
PsTransaction psTransaction = new PsTransaction();
foreach (int i in ids)
{
psUniteObjects.SetAsBooleanCut(i);
psUniteObjects.SetSubBodyType(SubBodyType.kAddBody);
psUniteObjects.CreateLogicalLink = false;
psUniteObjects.Apply();
psTransaction.EraseLongId((long)i);
psTransaction.Close();
}
PsUnits psUnits = new PsUnits();
PsMaterialTable psMaterialTable = new PsMaterialTable();
PsObjectProperties psObjectProperties = new PsObjectProperties();
psObjectProperties.Name = Type + " " + psUnits.ConvertToText(Diameter) + "x" + psUnits.ConvertToText(Length) +
" " + MaterialName;
psObjectProperties.Material = psMaterialTable.get_MaterialIndexFromName(MaterialName);
psObjectProperties.ColorIndex = Color;
PartListFlag = true;
psObjectProperties.PartListFlag = PartListFlag;
PartFamilyClassIndex = -1;
psObjectProperties.FamilyClass = PartFamilyClassIndex;
psObjectProperties.Length = Length;
psObjectProperties.writeTo(cylinderId);
PsPrimitive psPrimitive = new PsPrimitive();
psTransaction.GetObject((long)cylinderId, PsOpenMode.kForWrite, ref psPrimitive);
psPrimitive.writeProps(psObjectProperties);
psTransaction.Close();
}
public void ConvertToTCBolt(int ObjectId)
{
PsObjectProperties psObjectProperties = new PsObjectProperties();
PsTransaction psTransaction = new PsTransaction();
psObjectProperties.readFrom(ObjectId);
if (psObjectProperties.ObjectType == ObjectType.kBolt)
{
PsBolt standardBolt = new PsBolt();
psTransaction.GetObject((long)ObjectId, PsOpenMode.kForWrite, ref standardBolt);
if ((new ArrayList(new string[] {"A325 SHOP", "A325 FIELD", "A490 SHOP", "A490 FIELD"})).Contains(standardBolt.BoltStyleName))
{
SetStandardBoltParams(standardBolt.Diameter, standardBolt.BoltStyleName, standardBolt.LengthAddition);
Length = standardBolt.Length;
Diameter = standardBolt.Diameter;
KlemmLength = standardBolt.KlemmLength;
InsertPoint = standardBolt.InsertPoint;
XAxis = standardBolt.XAxis;
YAxis = standardBolt.YAxis;
PsPoint psEndPoint = new PsPoint();
PsVector tempVector = new PsVector();
tempVector.SetFromCrossProduct(XAxis, YAxis);
tempVector.Normalize();
ZAxis = tempVector.Clone();
psEndPoint = InsertPoint.Clone();
psEndPoint.AddScaled(ZAxis, KlemmLength);
CreateByTwoPoints(InsertPoint, psEndPoint);
psTransaction.Close();
psTransaction.EraseLongId((long)ObjectId);
}
psTransaction.Close();
}
}
}
public class AnchorBolt
{
public double Diameter;
public double Length;
public double Embedment;
public double PartThickness;
public double WasherOuterDiameter;
public double WasherThickness;
public double NutKeySize;
public double NutHeight;
public int ObjectId;
public string Type;
public string Name;
public string MaterialName;
public int MaterialIndex;
public int Color;
public bool PartListFlag;
public bool ModifyFlag;
public int PartFamilyClassIndex;
public PsPoint InsertPoint;
public PsVector XAxis;
public PsVector YAxis;
public PsVector ZAxis;
public AnchorBolt()
{
}
public void SetParams(string AnchorName, double AnchorDiameter, double AnchorEmbedment, double AnchorPartThickness, double AnchorLength)
{
Type = AnchorName;
Diameter = AnchorDiameter;
Embedment = AnchorEmbedment;
PartThickness = AnchorPartThickness;
Length = AnchorLength;
Color = 7;
PartListFlag = true;
PartFamilyClassIndex = -1;
if (AnchorDiameter == 0.25D)
{
WasherOuterDiameter = 0.734D;
WasherThickness = 0.071D;
NutKeySize = 0.500D;
NutHeight = 0.220D;
}
else if (AnchorDiameter == 0.375D)
{
WasherOuterDiameter = 1.000D;
WasherThickness = 0.071D;
NutKeySize = 0.688D;
NutHeight = 0.377D;
}
else if (AnchorDiameter == 0.5D)
{
WasherOuterDiameter = 1.250D;
WasherThickness = 0.112D;
NutKeySize = 0.875D;
NutHeight = 0.504D;
}
else if (AnchorDiameter == 0.625D)
{
WasherOuterDiameter = 1.75D;
WasherThickness = 0.112D;
NutKeySize = 1.062D;
NutHeight = 0.631D;
}
else if (AnchorDiameter == 0.75D)
{
WasherOuterDiameter = 2.000D;
WasherThickness = 0.112D;
NutKeySize = 1.250D;
NutHeight = 0.758D;
}
else if (AnchorDiameter == 0.875D)
{
WasherOuterDiameter = 2.250D;
WasherThickness = 0.174D;
NutKeySize = 1.438D;
NutHeight = 0.885D;
}
else if (AnchorDiameter == 1D)
{
WasherOuterDiameter = 2.500D;
WasherThickness = 0.174D;
NutKeySize = 1.625D;
NutHeight = 1.012D;
}
else if (AnchorDiameter == 1.125D)
{
WasherOuterDiameter = 2.750D;
WasherThickness = 0.174D;
NutKeySize = 1.812D;
NutHeight = 1.139D;
}
else
{
WasherOuterDiameter = 3.000D;
WasherThickness = 0.174D;
NutKeySize = 2.000D;
NutHeight = 1.251D;
}
}
public void GetNutAndWasherSizesByDiameter(double AnchorDiameter)
{
if (AnchorDiameter == 0.25D)
{
WasherThickness = 0.071D;
NutHeight = 0.220D;
}
else if (AnchorDiameter == 0.375D)
{
WasherThickness = 0.071D;
NutHeight = 0.377D;
}
else if (AnchorDiameter == 0.5D)
{
WasherThickness = 0.112D;
NutHeight = 0.504D;
}
else if (AnchorDiameter == 0.625D)
{
WasherThickness = 0.112D;
NutHeight = 0.631D;
}
else if (AnchorDiameter == 0.75D)
{
WasherThickness = 0.112D;
NutHeight = 0.758D;
}
else if (AnchorDiameter == 0.875D)
{
WasherThickness = 0.174D;
NutHeight = 0.885D;
}
else if (AnchorDiameter == 1D)
{
WasherThickness = 0.174D;
NutHeight = 1.012D;
}
else if (AnchorDiameter == 1.125D)
{
WasherThickness = 0.174D;
NutHeight = 1.139D;
}
else
{
WasherThickness = 0.174D;
NutHeight = 1.251D;
}
}
public int CreateAnchorCode111(PsPoint Point1, PsPoint Point2)
{
PsCreatePrimitive psCylinder = new PsCreatePrimitive();
PsCreatePrimitive psWasher = new PsCreatePrimitive();
PsCreatePrimitive psNut = new PsCreatePrimitive();
PsPolygon psNutPolygon = new PsPolygon();
PsVector psVector1 = new PsVector();
PsVector psVector2 = new PsVector();
PsVector psVector3 = new PsVector();
PsVector psVector = new PsVector();
psVector1.SetFromPoints(Point1, Point2);
psVector2 = psVector.GetPerpendicularVector(psVector1);
psVector3.SetFromCrossProduct(psVector1, psVector2);
InsertPoint = Point1;
psVector1.Normalize();
psVector2.Normalize();
psVector3.Normalize();
ZAxis = psVector1;
XAxis = psVector2;
YAxis = psVector3;
PsVector XAxisNegative = new PsVector();
XAxisNegative = XAxis.Clone();
XAxisNegative.Invert();
//Cylinder
PsPoint CylinderInsertPoint = new PsPoint();
CylinderInsertPoint = InsertPoint.Clone();
CylinderInsertPoint.AddScaled(ZAxis, -1*(Length - Embedment - PartThickness));
psCylinder.SetXYPlane(XAxis, YAxis);
psCylinder.SetInsertPoint(CylinderInsertPoint);
psCylinder.CreateCylinder(Diameter/2, Length);
// Washer
psWasher.SetXYPlane(XAxisNegative, YAxis);
psWasher.SetInsertPoint(InsertPoint);
psWasher.CreateCylinder(WasherOuterDiameter/2, WasherThickness);
// Nut
PsPoint nutInsertPoint = new PsPoint();
nutInsertPoint = InsertPoint.Clone();
nutInsertPoint.AddScaled(ZAxis, -1*WasherThickness);
psNutPolygon.createPolygon(6, NutKeySize/2, false);
psNut.SetXYPlane(XAxisNegative, YAxis);
psNut.SetPolygon(psNutPolygon);
psNut.SetInsertPoint(nutInsertPoint);
psNut.CreateExtrusion(NutHeight, 0D, 0D);
// Unite all
int cylinderId = psCylinder.ObjectId;
int washerId = psWasher.ObjectId;
int nutId = psNut.ObjectId;
int[] ids = {washerId, nutId};
PsCutObjects psUniteObjects = new PsCutObjects();
psUniteObjects.SetObjectId(cylinderId);
PsTransaction psTransaction = new PsTransaction();
foreach (int i in ids)
{
psUniteObjects.SetAsBooleanCut(i);
psUniteObjects.SetSubBodyType(SubBodyType.kAddBody);
psUniteObjects.CreateLogicalLink = false;
psUniteObjects.Apply();
psTransaction.EraseLongId((long)i);
psTransaction.Close();
}
PsUnits psUnits = new PsUnits();
PsObjectProperties psObjectProperties = new PsObjectProperties();
psObjectProperties.Name = Type + " " + psUnits.ConvertToText(Diameter) + "x" + psUnits.ConvertToText(Length);
psObjectProperties.ColorIndex = Color;
psObjectProperties.PartListFlag = PartListFlag;
psObjectProperties.FamilyClass = PartFamilyClassIndex;
psObjectProperties.Length = Length;
psObjectProperties.writeTo(cylinderId);
PsPrimitive psPrimitive = new PsPrimitive();
psTransaction.GetObject((long)cylinderId, PsOpenMode.kForWrite, ref psPrimitive);
psPrimitive.writeProps(psObjectProperties);
psTransaction.Close();
ObjectId = cylinderId;
return ObjectId;
}
}
}