-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutoDraw.txt
More file actions
1351 lines (1045 loc) · 43.4 KB
/
AutoDraw.txt
File metadata and controls
1351 lines (1045 loc) · 43.4 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
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports Inventor.PointIntentEnum
Imports Inventor.DimensionTypeEnum
Imports Inventor.DrawingCurveSegmentEnum
Imports Inventor.DrawingCurveEnum
Imports Inventor.CurveTypeEnum
Imports System.IO
Imports System.Text
Sub Main()
'write to iLogic Log
SharedVariable("LogVar") = "AutoDraw"
iLogicVB.RunExternalRule("Write SV to Log.iLogicVB")
'Ask to Create Drawing
AskCreateDrawing = vbYes 'MessageBox.Show("Would you like to Create Drawings for the Current Model?", "Drawing Automation",MessageBoxButtons.YesNo)
'If the User Presses YES
If AskCreateDrawing = vbYes Then 'AndAlso iProperties.Value("Custom", "HasDwg") = False Then
'Try
modelDoc = ThisApplication.ActiveDocument
oProps = modelDoc.PropertySets.Item("Design Tracking Properties")
oPN = oProps.Item("Part Number").Value
'read in the path to the templates and test that it Exists
dim strTemplatesPath as String = "C:\_vaultWIP\Designs\Templates\" 'getTemplatesFolderPath()
'messagebox.show(strTemplatesPath)
If strTemplatesPath.Length = 0 Then
MessageBox.Show("Error getting the path to the Templates location. Exiting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit sub
End if
If modelDoc.ComponentDefinition.Type = kAssemblyComponentDefinitionObject Then
If modelDoc.ComponentDefinition.IsiAssemblyMember = False Then
'iProperties.Value("Custom", "HasDwg") = True
iProperties.Value("Custom", "DETAILER") = ThisApplication.UserName
iProperties.Value("Project", "Creation Date") = DateString
Else
MessageBox.Show("This file is an iAssembly Member and properties cannot be added. Please check the table of the factory part, and make sure the properties are filled out correctly. ", "iPart/iAssembly", MessageBoxButtons.OK)
End If
Else if modelDoc.ComponentDefinition.Type = kPartComponentDefinitionObject Then
If modelDoc.ComponentDefinition.IsiPartMember = False And modelDoc.ComponentDefinition.IsContentMember = False Then
'iProperties.Value("Custom", "HasDwg") = True
iProperties.Value("Custom", "DETAILER") = ThisApplication.UserName
iProperties.Value("Project", "Creation Date") = DateString
Else
MessageBox.Show("This file is an iPart Member and properties cannot be added. Please check the table of the factory part, and make sure the properties are filled out correctly. ", "iPart/iAssembly", MessageBoxButtons.OK)
End If
End If
Dim uTemp as String
Dim Template as String
Dim TemplateList as New List(of String)
TemplateList.Add("TAIT US")
' TemplateList.Add("HKDL CSS")
' TemplateList.Add("Universal SM Japan")
' TemplateList.Add("Universal SM Hollywood")
' TemplateList.Add("Universal SM Florida")
TemplateList.Add("TAIT UK")
TemplateList.Add("DISN PORTER")
'Prompt user to select template
uTemp = InputListBox("Please select the template you would like to use: ", TemplateList, TemplateList(0), Title:= "Select Template", ListName := "Available Templates")
'Cancel on user command
'removed because InputListBox does not have a cancel button
' If uTemp = vbCancel Then
' Exit Sub
' End If
'select template based on user input - ADD TEMPLATES HERE!!!!!!
Select Case uTemp
Case TemplateList(0)
Template = strTemplatesPath + "TT_Part.dwg"
' Case TemplateList(1)
' Template = strTemplatesPath + "Disney\HKDL CSS Part Template.dwg"
' Case TemplateList(2)
' Template = strTemplatesPath + "Universal\US_JAPAN\_USJ_STANDARD TEMPLATE_SIZE B_11x17.dwg"
' Case TemplateList(3)
' Template = strTemplatesPath + "Universal\US_HOLLYWOOD\_USH_STANDARD TEMPLATE_SIZE B_11x17.dwg"
' Case TemplateList(4)
' Template = strTemplatesPath + "Universal\US_FLORIDA\_USF_STANDARD TEMPLATE_SIZE B_11x17.dwg"
Case TemplateList(1)
Template = strTemplatesPath + "Metric\UK TEST BORDER.dwg"
Case TemplateList(2)
Template = strTemplatesPath + "Disney\160398 PORTER DRAWING - INCH.dwg"
End Select
'prompt user to auto scale
Dim uScale As Boolean = True
uScale = InputRadioBox("Auto Scale?", "Yes", "No", uScale, Title := "Scale")
'Set the View Scales
Dim DrawingViewScale 'As Double
If uScale = True Then
If Not iProperties.Value("Custom", "LENGTH") = "" Then
DrawingViewScale = 4/iProperties.Value("Custom", "LENGTH")
Else
MessageBox.Show("The LENGTH property is empty. Setting Scale to 1:1", "No LENGTH provided", MessageBoxButtons.OK, MessageBoxIcon.Warning)
DrawingViewScale = 1
End If
Else
viewScale:
DrawingViewScale = InputBox("Enter Scale", "Scale", "1")
If DrawingViewScale = vbCancel Then
Exit sub
End if
If Not Double.TryParse(DrawingViewScale, 1.1) Then 'ShowNumber.Length = 6 Then
MsgBox("The scale value must be a decimal number (double), like 0.15 ")
Goto viewScale
End If
End If
'Dim ModelDocName As String
'ModelDocName = ThisDoc.FileName(False) 'without extension
oDwgDoc = CreateDrawing_PlaceViews(modelDoc, DrawingViewScale, Template, "Top_Right_Project", oBaseView, oRightSideView, oProjectView, oView4)
'Dim oBW as Double
'Dim oBH As Double
'oBW = oBaseView.Width
'oBH = oBaseView.Height
'MsgBox(oBW & " x " & oBH)
'CreateOverallDimension (oDwgDoc, oBaseView, YDIM, "Vertical", 0.75, "Left", False)
' ChuteTop = FindCurve (Assem_DrawingDoc, oBaseView, oBW, "Horizontal", "Top")
' MsgBox("1")
' FlangeEdge = FindCurve (Assem_DrawingDoc, oBaseView, oBH, "Vertical", "Right")
' CreateOverallDimension(ModelDrawingDoc, "Vertical", "Right", ChuteTop, "Top", FlangeEdge, "Right", 0.5)
'CreateLinearDimension (oDwgDoc, oBaseView, YDIM, "Vertical", 0.75, "Left", False)
'CreateLinearDimension (oDwgDoc, oBaseView, iProperties.Value("Custom", "WIDTH"), "Horizontal", -0.75, "Bottom", True)
'CreateLinearDimension (oDwgDoc, oRightSideView, iProperties.Value("Custom", "THICKNESS"), "Horizontal", 0.75, "Left", True)
'Save As oDrawingDoc (Path and File Name)
oPartPath = ThisDoc.Path 'Left(modelDoc.FullDocumentName, modelDoc.FullDocumentName.Length - modelDoc.FullFileName.Length)
oPartPathLength = Len(oPartPath)
oDrawingPath = Left(oPartPath, oPartPathLength)
'oDrawingDoc = oDrawingPath & "\" & oPN & ".dwg"
Try
oDwgDoc.SaveAs(oDrawingPath & "\" & oPN & ".dwg", False)
Catch
MessageBox.Show("Unable to save file. Check that a drawing does not already exist. ", "File Save Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
'Close the Template Drawing
'oDwgDoc.Close(True)
'Open the Newly Saved Drawing
'DrawingDoc = ThisApplication.Documents.Open(oDrawingDoc, True)
'Catch
'MessageBox.Show("An error has occured. Please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'Exit sub If uTemp = TemplateList(1) Then
'End try
End If
End Sub
Function CreateDrawing_PlaceViews (oPartDoc as Document, DrawingViewScale As Double, TemplatePath as String, ViewsToPlace As String, ByRef oBaseView As DrawingView, ByRef oView2 As DrawingView, ByRef oView3 As DrawingView, ByRef oView4 As DrawingView)
Dim oDrawDoc As DrawingDocument
'Dim oPartDoc As Document
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oPoint1 As Point2d
Dim oPoint2 As Point2d
Dim oPoint3 As Point2d
'oPartDoc = ThisDoc.Document
oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, TemplatePath, True)
oSheet = oDrawDoc.Sheets.Item(1)
oTG = ThisApplication.TransientGeometry
'Set points in order to get wanted View (ie. if 'Y' is the same and 'X' is greater or less, you will get a Side View)
oPoint1 = oTG.CreatePoint2d(10, 10)
oPoint2 = oTG.CreatePoint2d(10, 20)
oPoint3 = oTG.CreatePoint2d(30, 10)
oPoint4 = oTG.CreatePoint2d(30, 20)
Dim ViewStyles(0 To 3) As String
ViewStyles(0) = "Hidden Lines"
ViewStyles(1) = "Removed Hidden Lines"
ViewStyles(2) = "Shaded w/ Hidden Lines"
ViewStyles(3) = "Shaded w/ Removed Hidden Lines"
Dim uViewStyle As String
uViewStyle = ViewStyles(1) 'InputListBox("Select View Style", ViewStyles, ViewStyles(1), "Drawing View Style", "Select One")
Dim ViewStyle As DrawingViewStyleEnum
If uViewStyle = "Hidden Lines" Then
ViewStyle = 32257
Else If uViewStyle = "Removed Hidden Lines"
ViewStyle = 32258
Else If uViewStyle = "Shaded w/ Hidden Lines"
ViewStyle = 32259
Else If uViewStyle = "Shaded w/ Hidden Lines Removed"
ViewStyle = 32261
End If
'kFromBaseDrawingViewStyle = 32260
'kHiddenLineDrawingViewStyle = 32257
'kHiddenLineRemovedDrawingViewStyle = 32258
'kShadedDrawingViewStyle = 32259
'kShadedHiddenLineDrawingViewStyle = 32261
Dim oFlatViewOptions as NameValueMap
If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oFlatViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
oFlatViewOptions.Add("SheetMetalFoldedModel", False)
Try
FlatView = oSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(20, 15), DrawingViewScale, kFrontViewOrientation, ViewStyle, "Default", , oFlatViewOptions)
FlatView.ShowLabel = True
FlatView.Name = "FLAT PATTERN"
Catch
MessageBox.Show("An Error occurred when attempting to create a flat pattern. The rule cannot continue. Please correct the error and create a flat pattern manually, then try again. ", _
"Flat pattern error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
oDrawDoc.Close(False)
Exit Function
End Try
End If
'Create the Base View
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kFrontViewOrientation, ViewStyle, "Default")
'//////// Place the rest of the Projected Views According to the Parameter String Specified ////////////
If ViewsToPlace = "Top" Then
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Right"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Project"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Top_Right"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kFromBaseDrawingViewStyle, DrawingViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Top_Project"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kFromBaseDrawingViewStyle, DrawingViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Right_Project"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kFromBaseDrawingViewStyle, DrawingViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "Top_Right_Project"
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, kFromBaseDrawingViewStyle, DrawingViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, kFromBaseDrawingViewStyle, DrawingViewScale)
oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, kFromBaseDrawingViewStyle, DrawingViewScale)
Else If ViewsToPlace = "None" Then
'Only Place Base View, therefore do nothing
End If
'Return the Drawing Document
Return oDrawDoc
End Function
Function FindCurve (oDrawingDoc As DrawingDocument, oDrawingView As DrawingView, DimensionLength As Double, DirectionOfDim As String, DimensionLocation As String)
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)
Dim oDrawingCurve As DrawingCurve
Dim oTG As TransientGeometry
Dim Count As Integer
Dim DrawingViewScale As Double
DrawingViewScale = oDrawingView.Scale
oTG = ThisApplication.TransientGeometry
'////////// //////////////////
'////////// SEE 'CreateLinearDimension' FOR THIS PORTION OF CODE //////////////////
'////////// //////////////////
If DimensionLocation = "Top" Or DimensionLocation = "Right" Then
DrawingCurvePoint = oTG.CreatePoint2d(0, 0)
Else If DimensionLocation = "Bottom" Or DimensionLocation = "Left"
DrawingCurvePoint = oTG.CreatePoint2d(100, 100)
End If
DrawingCurvePointX = DrawingCurvePoint.x
Dim CurveCount As Integer
CurveCount = 0
For Each oDrawingCurve In oDrawingView.DrawingCurves
CurveCount = CurveCount + 1
Next
For StartCount = 1 To CurveCount
oDrawingCurve = oDrawingView.DrawingCurves.Item(StartCount)
If oDrawingCurve.CurveType = kLineSegmentCurve Then
Dim DimLength As DoubleForEquals
If DirectionOfDim = "Vertical" Then
DimLength = Abs(oDrawingCurve.StartPoint.y - oDrawingCurve.EndPoint.y)/DrawingViewScale/2.54
Else If DirectionOfDim = "Horizontal" Then
DimLength = Abs(oDrawingCurve.StartPoint.x - oDrawingCurve.EndPoint.x)/DrawingViewScale/2.54
End If
MsgBox("FC-A")
MsgBox(DimensionLength)
If Abs(DimLength - DimensionLength) < 0.01 Then
If DirectionOfDim = "Vertical" And DimensionLocation = "Right" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Vertical" And DimensionLocation = "Left" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Top" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Bottom" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
End If
End If
End If
Next
Return CorrectCurve
End Function
Function CreateLinearDimension (oDrawingDoc As DrawingDocument, oDrawingView As DrawingView, DimensionLength As DoubleForEquals, DirectionOfDim As String, OffsetDistance As Double, DimensionLocation As String, ReferencedDim As Boolean)
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)
Dim oDrawingCurve As DrawingCurve
Dim oTG As TransientGeometry
Dim Count As Integer
Dim DrawingViewScale As Double
DrawingViewScale = oDrawingView.Scale
oTG = ThisApplication.TransientGeometry
'Set up Phantom points in order to locate the Wanted lines
'(If you want To find the lower line, you must start With a higher point And work your way down)
If DimensionLocation = "Top" Or DimensionLocation = "Right" Then
DrawingCurvePoint = oTG.CreatePoint2d(0, 0)
Else If DimensionLocation = "Bottom" Or DimensionLocation = "Left"
DrawingCurvePoint = oTG.CreatePoint2d(100, 100)
End If
'The 'X' is used for both the 'X' and 'Y' when locating the point
'It Is only a place holder so that the variables match for programming
DrawingCurvePointX = DrawingCurvePoint.x
Dim CurveCount As Integer
CurveCount = 0
'Find the amount of curves in the specified view
For Each oDrawingCurve In oDrawingView.DrawingCurves
CurveCount = CurveCount + 1
Next
'From the First Curve until the Last Curve (All curves based on the last For loop)
For StartCount = 1 To CurveCount
'Select the curve
oDrawingCurve = oDrawingView.DrawingCurves.Item(StartCount)
'If this curve is Linear
If oDrawingCurve.CurveType = kLineSegmentCurve Then
Dim DimLength As DoubleForEquals
'Get the Length of the Curve based on the Orientation passed into the Sub
'Abs(a - b) gives you the number whether it is a negative number or positive, it will always convert to positive
'This Number is in Sheet Space and 'cm', Divide by the View Scale and by 2.54 to convert to Model Space and 'in'
If DirectionOfDim = "Vertical" Then
DimLength = Abs(oDrawingCurve.StartPoint.y - oDrawingCurve.EndPoint.y)/DrawingViewScale/2.54
Else If DirectionOfDim = "Horizontal" Then
DimLength = Abs(oDrawingCurve.StartPoint.x - oDrawingCurve.EndPoint.x)/DrawingViewScale/2.54
End If
'If this Curve is Equal to the Wanted Dimension Specified by the Parameter Passed into the Sub (Within Tolerance)
If Abs(DimLength - DimensionLength) < 0.0001 Then
'Based on the direction you want the line to be towards, this computes appropriate calculations for each direction
'If the calculation Proves to be right (This Curve is farther towards the specified side than the previous curve)
'Then the current curve will be saved as the Correct one
If DirectionOfDim = "Vertical" And DimensionLocation = "Right" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Vertical" And DimensionLocation = "Left" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Top" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Bottom" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
End If
End If
End If
Next
Dim oDim As LinearGeneralDimension
Dim oPt As Point2d
Dim oPlaceDimX As Double
Dim oPlaceDimY As Double
Dim oIntent1 As GeometryIntent
Dim oIntent2 As GeometryIntent
'Create the Intent points based on the Correct Curve found through the For Loop
oIntent1 = oSheet.CreateGeometryIntent(CorrectCurve, kStartPointIntent)
oIntent2 = oSheet.CreateGeometryIntent(CorrectCurve, kEndPointIntent)
'Offset the Text in the appropriate direction based on the Curve orientation and center
If DirectionOfDim = "Vertical" Then
oPlaceDimX = CorrectCurve.MidPoint.x + OffsetDistance
oPlaceDimY = CorrectCurve.MidPoint.y
Else If DirectionOfDim = "Horizontal"
oPlaceDimX = CorrectCurve.MidPoint.x
oPlaceDimY = CorrectCurve.MidPoint.y + OffsetDistance
End If
'Create the Point using these locations
oPt = oTG.CreatePoint2d(oPlaceDimX, oPlaceDimY)
'Set the Appropriate Style based on the Parameter passed into the Sub
'(These Styles are pre set up in the Drawing Template)
Dim DimStyle As DimensionStyle
If ReferencedDim = False Then
DimStyle = oDrawingDoc.StylesManager.DimensionStyles.Item("TT_2_Dec")
Else If ReferencedDim = True
DimStyle = oDrawingDoc.StylesManager.DimensionStyles.Item("REF TT_2_Dec")
End If
'Set the Type of dimension to create
Dim TypeOfDim As String
If DirectionOfDim = "Vertical" Then
TypeOfDim = kVerticalDimensionType
Else If DirectionOfDim = "Horizontal"
TypeOfDim = kHorizontalDimensionType
End If
'Create the Dimension and Re-Center the text inbetween the leaders
Dim oDimension As DrawingDimension
oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oIntent1, oIntent2, TypeOfDim, True, DimStyle)
oDimension.CenterText
'Return this Dimension
Return oDimension
End Function
Function CreateAlignedDimension (oDrawingDoc As DrawingDocument, oDrawingView As DrawingView, DimensionLength As DoubleForEquals, DirectionOfDim As String, OffsetDistance As Double, DimensionLocation As String, DimensionType As String, ReferencedDim As Boolean)
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)
Dim oDrawingCurve As DrawingCurve
Dim CorrectCurve As DrawingCurve
Dim oTG As TransientGeometry
Dim StartCount As Integer
Dim DrawingViewScale As Double
DrawingViewScale = oDrawingView.Scale
oTG = ThisApplication.TransientGeometry
'Set up Phantom points in order to locate the Wanted lines
'(If you want To find the lower line, you must start With a higher point And work your way down)
If DimensionLocation = "Top" Or DimensionLocation = "Right" Then
DrawingCurvePoint = oTG.CreatePoint2d(0, 0)
Else If DimensionLocation = "Bottom" Or DimensionLocation = "Left"
DrawingCurvePoint = oTG.CreatePoint2d(100, 100)
End If
'The 'X' is used for both the 'X' and 'Y' when locating the point
'It Is only a place holder so that the variables match for programming
DrawingCurvePointX = DrawingCurvePoint.x
Dim CurveCount As Integer
CurveCount = 0
'Find the amount of curves in the specified view
For Each oDrawingCurve In oDrawingView.DrawingCurves
CurveCount = CurveCount + 1
Next
'From the First Curve until the Last Curve (All curves based on the last For loop)
For StartCount = 1 To CurveCount
'Select the Curve
oDrawingCurve = oDrawingView.DrawingCurves.Item(StartCount)
'If this Curve is linear
If oDrawingCurve.CurveType = kLineSegmentCurve Then
Dim DimLength As DoubleForEquals
'Get the Length of the Curve based on the Orientation passed into the Sub
'Abs(a - b) gives you the number whether it is a negative number or positive, it will always convert to positive
'This Number is in Sheet Space and 'cm', Divide by the View Scale and by 2.54 to convert to Model Space and 'in'
If DirectionOfDim = "Vertical" Then
DimLength = Abs(oDrawingCurve.StartPoint.y - oDrawingCurve.EndPoint.y)/DrawingViewScale/2.54
Else If DirectionOfDim = "Horizontal" Then
DimLength = Abs(oDrawingCurve.StartPoint.x - oDrawingCurve.EndPoint.x)/DrawingViewScale/2.54
End If
'If this Curve is Equal to the Wanted Dimension Specified by the Parameter Passed into the Sub (Within Tolerance)
If Abs(DimLength - DimensionLength) < 0.0001 Then
'Based on the direction you want the line to be towards, this computes appropriate calculations for each direction
'If the calculation Proves to be right (This Curve is farther towards the specified side than the previous curve)
'Then the current curve will be saved as the Correct one
If DirectionOfDim = "Vertical" And DimensionLocation = "Right" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX < oDrawingCurve.EndPoint.x
DrawingCurvePointX = oDrawingCurve.EndPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Vertical" And DimensionLocation = "Left" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX > oDrawingCurve.EndPoint.x
DrawingCurvePointX = oDrawingCurve.EndPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Top" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX < oDrawingCurve.EndPoint.y
DrawingCurvePointX = oDrawingCurve.EndPoint.y
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Bottom" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX > oDrawingCurve.EndPoint.y
DrawingCurvePointX = oDrawingCurve.EndPoint.y
CorrectCurve = oDrawingCurve
End If
End If
End If
End If
Next
Dim oDim As LinearGeneralDimension
Dim oPt As Point2d
Dim oPlaceDimX As Double
Dim oPlaceDimY As Double
Dim oIntent1 As GeometryIntent
Dim oIntent2 As GeometryIntent
'Create the Intent points based on the Correct Curve found through the For Loop
oIntent1 = oSheet.CreateGeometryIntent(CorrectCurve, kStartPointIntent)
oIntent2 = oSheet.CreateGeometryIntent(CorrectCurve, kEndPointIntent)
'Brings the Dimension Text to the furthest Point based on the whether Offset distance is '-' or '+'
'This is to keep the same effect in using OffsetDistance as a Linear Dimension
Dim LineOffset As Double
If OffsetDistance < 0 Then
If DirectionOfDim = "Vertical" Then
LineOffset = -Abs(CorrectCurve.StartPoint.x - CorrectCurve.EndPoint.x)/2 'Horizontal
Else If DirectionOfDim = "Horizontal"
LineOffset = -Abs(CorrectCurve.StartPoint.y - CorrectCurve.EndPoint.y)/2 'Vertical
End If
Else If OffsetDistance >= 0
If DirectionOfDim = "Vertical" Then
LineOffset = Abs(CorrectCurve.StartPoint.x - CorrectCurve.EndPoint.x)/2 'Horizontal
Else If DirectionOfDim = "Horizontal"
LineOffset = Abs(CorrectCurve.StartPoint.y - CorrectCurve.EndPoint.y)/2 'Vertical
End If
End If
'Offset the Text in the appropriate direction based on the Curve orientation and center
If DirectionOfDim = "Vertical" Then
oPlaceDimX = CorrectCurve.MidPoint.x + LineOffset + OffsetDistance
oPlaceDimY = CorrectCurve.MidPoint.y
Else If DirectionOfDim = "Horizontal"
oPlaceDimX = CorrectCurve.MidPoint.x
oPlaceDimY = CorrectCurve.MidPoint.y + LineOffset + OffsetDistance
End If
'Create the Point using the above Values
oPt = oTG.CreatePoint2d(oPlaceDimX, oPlaceDimY)
'Set the Appropriate Style based on the Parameter passed into the Sub
'(These Styles are pre set up in the Drawing Template)
Dim DimStyle As DimensionStyle
If ReferencedDim = False Then
DimStyle = oDrawingDoc.StylesManager.DimensionStyles.Item("GT - Fraction (ANSI)")
Else If ReferencedDim = True
DimStyle = oDrawingDoc.StylesManager.DimensionStyles.Item("GT - Reference Fraction (ANSI)")
End If
'Set the type of dimension to create
Dim TypeOfDim As String
If DimensionType = "Vertical" Then
TypeOfDim = kVerticalDimensionType
Else If DimensionType = "Horizontal"
TypeOfDim = kHorizontalDimensionType
Else If DimensionType = "Aligned"
TypeOfDim = kAlignedDimensionType
End If
'Create the Dimension and Re-Center the text inbetween the leaders
Dim oDimension As DrawingDimension
oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oIntent1, oIntent2, TypeOfDim, True, DimStyle)
'Return this Dimension
Return oDimension
End Function
Function CreateDetailView (oDrawingDoc As DrawingDocument, oDrawingView As DrawingView, ScaleSize As Double, DimensionLength As DoubleForEquals, DirectionOfDim As String, DimensionLocation As String, PointLocation As String, Radius As Double)
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)
Dim oDrawingCurve As DrawingCurve
Dim CorrectCurve As DrawingCurve
Dim oTG As TransientGeometry
Dim StartCount As Integer
Dim oDetailView As DetailDrawingView
Dim DrawingViewScale As Double
DrawingViewScale = oDrawingView.Scale
oTG = ThisApplication.TransientGeometry
'////////// //////////////////
'////////// SEE 'CreateLinearDimension' FOR THIS PORTION OF CODE //////////////////
'////////// //////////////////
If DimensionLocation = "Top" Or DimensionLocation = "Right" Then
DrawingCurvePoint = oTG.CreatePoint2d(0, 0)
Else If DimensionLocation = "Bottom" Or DimensionLocation = "Left"
DrawingCurvePoint = oTG.CreatePoint2d(100, 100)
End If
DrawingCurvePointX = DrawingCurvePoint.x
Dim CurveCount As Integer
CurveCount = 0
For Each oDrawingCurve In oDrawingView.DrawingCurves
CurveCount = CurveCount + 1
Next
For StartCount = 1 To CurveCount
oDrawingCurve = oDrawingView.DrawingCurves.Item(StartCount)
If oDrawingCurve.CurveType = kLineSegmentCurve Then
Dim DimLength As DoubleForEquals
If DirectionOfDim = "Vertical" Then
DimLength = Abs(oDrawingCurve.StartPoint.y - oDrawingCurve.EndPoint.y)/DrawingViewScale/2.54
Else If DirectionOfDim = "Horizontal" Then
DimLength = Abs(oDrawingCurve.StartPoint.x - oDrawingCurve.EndPoint.x)/DrawingViewScale/2.54
End If
If Abs(DimLength - DimensionLength) < 0.0001 Then
If DirectionOfDim = "Vertical" And DimensionLocation = "Right" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX < oDrawingCurve.EndPoint.x
DrawingCurvePointX = oDrawingCurve.EndPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Vertical" And DimensionLocation = "Left" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.x
DrawingCurvePointX = oDrawingCurve.StartPoint.x
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX > oDrawingCurve.EndPoint.x
DrawingCurvePointX = oDrawingCurve.EndPoint.x
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Top" Then
If DrawingCurvePointX < oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX < oDrawingCurve.EndPoint.y
DrawingCurvePointX = oDrawingCurve.EndPoint.y
CorrectCurve = oDrawingCurve
End If
Else If DirectionOfDim = "Horizontal" And DimensionLocation = "Bottom" Then
If DrawingCurvePointX > oDrawingCurve.StartPoint.y
DrawingCurvePointX = oDrawingCurve.StartPoint.y
CorrectCurve = oDrawingCurve
End If
If DrawingCurvePointX > oDrawingCurve.EndPoint.y
DrawingCurvePointX = oDrawingCurve.EndPoint.y
CorrectCurve = oDrawingCurve
End If
End If
End If
End If
Next
Dim StartPoint As Point2d
Dim EndPoint As Point2d
Dim CenterPoint As Point2d
Dim Coords As Point2d
'Set the Start Point and End Point to the correct curve
StartPoint = CorrectCurve.StartPoint
EndPoint = CorrectCurve.EndPoint
'Find the Center Point of the Detail based on the Parameters passed into the Sub
If DirectionOfDim = "Horizontal" And PointLocation = "Left" Then
If StartPoint.x < EndPoint.x Then
CenterPoint = StartPoint
Else
CenterPoint = EndPoint
End If
Else If DirectionOfDim = "Horizontal" And PointLocation = "Right"
If StartPoint.x > EndPoint.x Then
CenterPoint = StartPoint
Else
CenterPoint = EndPoint
End If
Else If DirectionOfDim = "Vertical" And PointLocation = "Top"
If StartPoint.y > EndPoint.y Then
CenterPoint = StartPoint
Else
CenterPoint = EndPoint
End If
Else If DirectionOfDim = "Vertical" And PointLocation = "Bottom"
If StartPoint.y < EndPoint.y Then
CenterPoint = StartPoint
Else
CenterPoint = EndPoint
End If
End If
'Create a phantom point to place the view (Changed after Rule in the Drawing template is run)
Dim ViewPoint As Point2d
ViewPoint = oTG.CreatePoint2d(5, 5)
'Creates an anchor point to attach the Detail to
'(This Is Not the Detail View itself but the little circle that creates the view)
Dim oAttachPoint As GeometryIntent
oAttachPoint = oSheet.CreateGeometryIntent(CorrectCurve, kStartPointIntent)
'Create the Detail View
oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, ViewPoint, kFromBaseDrawingViewStyle, True, CenterPoint, Radius, oAttachPoint, ScaleSize, False)
'Return the View
Return oDetailView
End Function
Sub AlignText (TargetText As DrawingDimension, DestinationText11 As DrawingDimension, DestinationText22 As DrawingDimension, Direction As String, Side As String)
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim Num11 As Double
Dim Num22 As Double
Dim StartPoint11 As Point2d
Dim EndPoint11 As Point2d
Dim Point11 As Point2d
Dim StartPoint22 As Point2d
Dim EndPoint22 As Point2d
Dim Point22 As Point2d
Dim CountStart As Integer
Dim CountEnd As Integer
CountEnd = 2
'Set the Points
Point11 = oTG.CreatePoint2d(0, 0)
Point22 = oTG.CreatePoint2d(0, 0)
'Set the Start Points and end points for both possible sides of the text alignment
StartPoint11 = DestinationText11.IntentOne.PointOnSheet
EndPoint11 = DestinationText11.IntentTwo.PointOnSheet
StartPoint22 = DestinationText22.IntentOne.PointOnSheet
EndPoint22 = DestinationText22.IntentTwo.PointOnSheet
For CountStart = 1 To CountEnd
Dim StartPoint As Point2d
Dim EndPoint As Point2d
Dim CorrectPoint As Point2d
StartPoint = oTG.CreatePoint2d(0, 0)
EndPoint = oTG.CreatePoint2d(0, 0)
CorrectPoint = oTG.CreatePoint2d(0, 0)
'Because the same calculations are needed for 3 different sets of variable, the variables will be replaced
'with each cycle of the For loop
If CountStart = 1 Then
StartPoint = StartPoint11
EndPoint = EndPoint11
CorrectPoint = Point11
Else If CountStart = 2
StartPoint = StartPoint22
EndPoint = EndPoint22
CorrectPoint = Point22
End If
If Side = "Left" Then
If StartPoint.x < EndPoint.x Then
CorrectPoint = StartPoint
Else
CorrectPoint = EndPoint
End If
Else If Side = "Right" Then
If StartPoint.x > EndPoint.x Then
CorrectPoint = StartPoint
Else
CorrectPoint = EndPoint
End If
Else If Side = "Bottom" Then
If StartPoint.y < EndPoint.y Then
CorrectPoint = StartPoint
Else
CorrectPoint = EndPoint
End If
Else If Side = "Top" Then
If StartPoint.y > EndPoint.y Then
CorrectPoint = StartPoint
Else
CorrectPoint = EndPoint
End If
End If
'Set the Variable to the Correct one
If CountStart = 1 Then
Point11 = CorrectPoint
Else If CountStart = 2
Point22 = CorrectPoint
End If
Next
'Set the Text to Align the Target Text with
'You'll want to align with the smaller Line
If Side = "Left"
If Point11.x > Point22.x Then
DestinationText = DestinationText11
Else
DestinationText = DestinationText22
End If
Else If Side = "Right"
If Point11.x < Point22.x Then
DestinationText = DestinationText11
Else
DestinationText = DestinationText22
End If
Else If Side = "Top"
If Point11.y < Point22.y Then
DestinationText = DestinationText11
Else
DestinationText = DestinationText22
End If
Else If Side = "Bottom"
If Point11.y > Point22.y Then
DestinationText = DestinationText11
Else
DestinationText = DestinationText22
End If
End If
Dim dPosition As Double
Dim oPosition As Point2d
'Get the Origin Point of the Target Text
oPosition = TargetText.Text.Origin
'Align the Target Text according to the proper direction
If Direction = "Vertical" Then
dPosition = DestinationText.Text.Origin.Y
oPosition.Y = dPosition
Else If Direction = "Horizontal" Then
dPosition = DestinationText.Text.Origin.X
oPosition.X = dPosition
End If
'Set the Target text Origin
TargetText.Text.Origin = oPosition
End Sub
Sub CreateText (oDrawingDoc As DrawingDocument, ViewNumber As Double, oText As String, OffsetDistance As Double)
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oTG As TransientGeometry
Dim oPoint As Point2d
Dim TextPoint As Point2d
Dim ViewWidth As Double
Dim TextWidth As Double
'Set the Drawing View based on the Index passed into the sub
oSheet = oDrawingDoc.Sheets.Item(1)
oDrawingView = oSheet.DrawingViews.Item(ViewNumber)