-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChapter9.txt
788 lines (654 loc) · 24.4 KB
/
Chapter9.txt
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
Public Sub SetViewpoint(Optional Zoom As Boolean = False, _
Optional X As Double = 1, _
Optional Y As Double = -2, _
Optional Z As Double = 1)
Dim dblDirection(2) As Double
dblDirection(0) = X: dblDirection(1) = Y: dblDirection(2) = Z
With ThisDrawing
.Preferences.ContourLinesPerSurface = 10 ' set surface countours
.ActiveViewport.Direction = dblDirection ' assign new direction
.ActiveViewport = .ActiveViewport ' force a viewport update
If Zoom Then .Application.ZoomAll ' zoomall if requested
End With
End Sub
Public Sub TestAddBox()
Dim varPick As Variant
Dim dblLength As Double
Dim dblWidth As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint Zoom:=True
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick a corner point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblLength = .GetDistance(varPick, vbCr & "Enter the X length: ")
.InitializeUserInput 1 + 2 + 4, ""
dblWidth = .GetDistance(varPick, vbCr & "Enter the Y width: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & "Enter the Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0) + (dblLength / 2)
dblCenter(1) = varPick(1) + (dblWidth / 2)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddBox(dblCenter, dblLength, _
dblWidth, dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddCone()
Dim varPick As Variant
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick the base center point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblRadius = .GetDistance(varPick, vbCr & "Enter the radius: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & "Enter the Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0)
dblCenter(1) = varPick(1)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddCone(dblCenter, dblRadius, _
dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddCylinder()
Dim varPick As Variant
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick the base center point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblRadius = .GetDistance(varPick, vbCr & "Enter the radius: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & "Enter the Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0)
dblCenter(1) = varPick(1)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddCylinder(dblCenter, dblRadius, dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddSphere()
Dim varPick As Variant
Dim dblRadius As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick the center point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblRadius = .GetDistance(varPick, vbCr & "Enter the radius: ")
End With
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddSphere(varPick, dblRadius)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddTorus()
Dim pntPick As Variant
Dim pntRadius As Variant
Dim dblRadius As Double
Dim dblTube As Double
Dim objEnt As Acad3DSolid
Dim intI As Integer
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
pntPick = .GetPoint(, vbCr & "Pick the center point: ")
.InitializeUserInput 1
pntRadius = .GetPoint(pntPick, vbCr & "Pick a radius point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblTube = .GetDistance(pntRadius, vbCr & "Enter the tube radius: ")
End With
'' calculate radius from points
For intI = 0 To 2
dblRadius = dblRadius + (pntPick(intI) - pntRadius(intI)) ^ 2
Next
dblRadius = Sqr(dblRadius)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddTorus(pntPick, dblRadius, dblTube)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddWedge()
Dim varPick As Variant
Dim dblLength As Double
Dim dblWidth As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick a base corner point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblLength = .GetDistance(varPick, vbCr & "Enter the base X length: ")
.InitializeUserInput 1 + 2 + 4, ""
dblWidth = .GetDistance(varPick, vbCr & "Enter the base Y width: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & "Enter the base Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0) + (dblLength / 2)
dblCenter(1) = varPick(1) + (dblWidth / 2)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddWedge(dblCenter, dblLength, _
dblWidth, dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddEllipticalCone()
Dim varPick As Variant
Dim dblXAxis As Double
Dim dblYAxis As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick a base center point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblXAxis = .GetDistance(varPick, vbCr & "Enter the X eccentricity: ")
.InitializeUserInput 1 + 2 + 4, ""
dblYAxis = .GetDistance(varPick, vbCr & "Enter the Y eccentricity: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & "Enter the cone Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0)
dblCenter(1) = varPick(1)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddEllipticalCone(dblCenter, _
dblXAxis, dblYAxis, dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddEllipticalCylinder()
Dim varPick As Variant
Dim dblXAxis As Double
Dim dblYAxis As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
'' set the default viewpoint
SetViewpoint
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varPick = .GetPoint(, vbCr & "Pick a base center point: ")
.InitializeUserInput 1 + 2 + 4, ""
dblXAxis = .GetDistance(varPick, vbCr & "Enter the X eccentricity: ")
.InitializeUserInput 1 + 2 + 4, ""
dblYAxis = .GetDistance(varPick, vbCr & "Enter the Y eccentricity: ")
.InitializeUserInput 1 + 2 + 4, ""
dblHeight = .GetDistance(varPick, vbCr & _
"Enter the cylinder Z height: ")
End With
'' calculate center point from input
dblCenter(0) = varPick(0)
dblCenter(1) = varPick(1)
dblCenter(2) = varPick(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddEllipticalCylinder(dblCenter, _
dblXAxis, dblYAxis, dblHeight)
objEnt.Update
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddExtrudedSolid()
Dim varCenter As Variant
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblTaper As Double
Dim strInput As String
Dim varRegions As Variant
Dim objEnts() As AcadEntity
Dim objEnt As Acad3DSolid
Dim varItem As Variant
On Error GoTo Done
'' get input from user
With ThisDrawing.Utility
.InitializeUserInput 1
varCenter = .GetPoint(, vbCr & "Pick the center point: ")
.InitializeUserInput 1 + 2 + 4
dblRadius = .GetDistance(varCenter, vbCr & "Indicate the radius: ")
.InitializeUserInput 1 + 2 + 4
dblHeight = .GetDistance(varCenter, vbCr & _
"Enter the extrusion height: ")
'' get the taper type
.InitializeUserInput 1, "Expand Contract None"
strInput = .GetKeyword(vbCr & _
"Extrusion taper [Expand/Contract/None]: ")
'' if none, taper = 0
If strInput = "None" Then
dblTaper = 0
'' otherwise, get the taper angle
Else
.InitializeUserInput 1 + 2 + 4
dblTaper = .GetReal("Enter the taper angle ( in degrees): ")
dblTaper = .AngleToReal(CStr(dblTaper), acDegrees)
'' if expanding, negate the angle
If strInput = "Expand" Then dblTaper = -dblTaper
End If
End With
'' draw the entities
With ThisDrawing.ModelSpace
'' draw the outer region (circle)
ReDim objEnts(0)
Set objEnts(0) = .AddCircle(varCenter, dblRadius)
'' create the region
varRegions = .AddRegion(objEnts)
'' extrude the solid
Set objEnt = .AddExtrudedSolid(varRegions(0), dblHeight, dblTaper)
'' update the extruded solid
objEnt.Update
End With
Done:
If Err Then MsgBox Err.Description
'' delete the temporary geometry
For Each varItem In objEnts
varItem.Delete
Next
For Each varItem In varRegions
varItem.Delete
Next
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddExtrudedSolidAlongPath()
Dim objPath As AcadSpline
Dim varPick As Variant
Dim intI As Integer
Dim dblCenter(2) As Double
Dim dblRadius As Double
Dim objCircle As AcadCircle
Dim objEnts() As AcadEntity
Dim objShape As Acad3DSolid
Dim varRegions As Variant
Dim varItem As Variant
'' set default viewpoint
SetViewpoint
'' pick path and calculate shape points
With ThisDrawing.Utility
'' pick the path
On Error Resume Next
.GetEntity objPath, varPick, "Pick a Spline for the path"
If Err Then
MsgBox "You did not pick a spline"
Exit Sub
End If
objPath.Color = acGreen
For intI = 0 To 2
dblCenter(intI) = objPath.FitPoints(intI)
Next
.InitializeUserInput 1 + 2 + 4
dblRadius = .GetDistance(dblCenter, vbCr & "Indicate the radius: ")
End With
'' draw the circular region, then extrude along path
With ThisDrawing.ModelSpace
'' draw the outer region (circle)
ReDim objEnts(0)
Set objCircle = .AddCircle(dblCenter, dblRadius)
objCircle.Normal = objPath.StartTangent
Set objEnts(0) = objCircle
'' create the region
varRegions = .AddRegion(objEnts)
Set objShape = .AddExtrudedSolidAlongPath(varRegions(0), objPath)
objShape.Color = acRed
End With
'' delete the temporary geometry
For Each varItem In objEnts: varItem.Delete: Next
For Each varItem In varRegions: varItem.Delete: Next
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestAddRevolvedSolid()
Dim objShape As AcadLWPolyline
Dim varPick As Variant
Dim objEnt As AcadEntity
Dim varPnt1 As Variant
Dim dblOrigin(2) As Double
Dim varVec As Variant
Dim dblAngle As Double
Dim objEnts() As AcadEntity
Dim varRegions As Variant
Dim varItem As Variant
'' set default viewpoint
SetViewpoint
'' draw the shape and get rotation from user
With ThisDrawing.Utility
'' pick a shape
On Error Resume Next
.GetEntity objShape, varPick, "pick a polyline shape"
If Err Then
MsgBox "You did not pick the correct type of shape"
Exit Sub
End If
On Error GoTo Done
objShape.Closed = True
'' add pline to region input array
ReDim objEnts(0)
Set objEnts(0) = objShape
'' get the axis points
.InitializeUserInput 1
varPnt1 = .GetPoint(, vbLf & "Pick an origin of revolution: ")
.InitializeUserInput 1
varVec = .GetPoint(dblOrigin, vbLf & _
"Indicate the axis of revolution: ")
'' get the angle to revolve
.InitializeUserInput 1
dblAngle = .GetAngle(, vbLf & "Angle to revolve: ")
End With
'' make the region, then revolve it into a solid
With ThisDrawing.ModelSpace
'' make region from closed pline
varRegions = .AddRegion(objEnts)
'' revolve solid about axis
Set objEnt = .AddRevolvedSolid(varRegions(0), varPnt1, varVec, _
dblAngle)
objEnt.Color = acRed
End With
Done:
If Err Then MsgBox Err.Description
'' delete the temporary geometry
For Each varItem In objEnts: varItem.Delete: Next
If Not IsEmpty(varRegions) Then
For Each varItem In varRegions: varItem.Delete: Next
End If
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestBoolean()
Dim objFirst As Acad3DSolid
Dim objSecond As Acad3DSolid
Dim varPick As Variant
Dim strOp As String
On Error Resume Next
With ThisDrawing.Utility
'' get first solid from user
.GetEntity objFirst, varPick, vbCr & "Pick a solid to edit: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
'' highlight entity
objFirst.Highlight True
objFirst.Update
'' get second solid from user
.GetEntity objSecond, varPick, vbCr & "Pick a solid to combine: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
'' exit if they're the same
If objFirst Is objSecond Then
MsgBox "You must pick 2 different solids"
Exit Sub
End If
'' highlight entity
objSecond.Highlight True
objSecond.Update
'' get boolean operation
.InitializeUserInput 1, "Intersect Subtract Union"
strOp = .GetKeyword(vbCr & _
"Boolean operation [Intersect/Subtract/Union]: ")
'' combine the solids
Select Case strOp
Case "Intersect": objFirst.Boolean acIntersection, objSecond
Case "Subtract": objFirst.Boolean acSubtraction, objSecond
Case "Union": objFirst.Boolean acUnion, objSecond
End Select
'' highlight entity
objFirst.Highlight False
objFirst.Update
End With
'' shade the view, and start the interactive orbit command
ThisDrawing.SendCommand "_shade" & vbCr & "_orbit" & vbCr
End Sub
Public Sub TestInterference()
Dim objFirst As Acad3DSolid
Dim objSecond As Acad3DSolid
Dim objNew As Acad3DSolid
Dim varPick As Variant
Dim varNewPnt As Variant
On Error Resume Next
'' set default viewpoint
SetViewpoint
With ThisDrawing.Utility
'' get first solid from user
.GetEntity objFirst, varPick, vbCr & "Pick the first solid: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
'' highlight entity
objFirst.Highlight True
objFirst.Update
'' get second solid from user
.GetEntity objSecond, varPick, vbCr & "Pick the second solid: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
'' exit if they're the same
If objFirst Is objSecond Then
MsgBox "You must pick 2 different solids"
Exit Sub
End If
'' highlight entity
objSecond.Highlight True
objSecond.Update
'' combine the solids
Set objNew = objFirst.CheckInterference(objSecond, True)
If objNew Is Nothing Then
MsgBox "Those solids don't intersect"
Else
'' highlight new solid
objNew.Highlight True
objNew.Color = acWhite
objNew.Update
'' move new solid
.InitializeUserInput 1
varNewPnt = .GetPoint(varPick, vbCr & "Pick a new location: ")
objNew.Move varPick, varNewPnt
End If
'' dehighlight entities
objFirst.Highlight False
objFirst.Update
objSecond.Highlight False
objSecond.Update
End With
'' shade the view, and start the interactive orbit command
ThisDrawing.SendCommand "_shade" & vbCr & "_orbit" & vbCr
End Sub
Public Sub TestSliceSolid()
Dim objFirst As Acad3DSolid
Dim objSecond As Acad3DSolid
Dim objNew As Acad3DSolid
Dim varPick As Variant
Dim varPnt1 As Variant
Dim varPnt2 As Variant
Dim varPnt3 As Variant
Dim strOp As String
Dim blnOp As Boolean
On Error Resume Next
With ThisDrawing.Utility
'' get first solid from user
.GetEntity objFirst, varPick, vbCr & "Pick a solid to slice: "
If Err Then
MsgBox "That is not a 3DSolid"
Exit Sub
End If
'' highlight entity
objFirst.Highlight True
objFirst.Update
.InitializeUserInput 1
varPnt1 = .GetPoint(varPick, vbCr & "Pick first slice point: ")
.InitializeUserInput 1
varPnt2 = .GetPoint(varPnt1, vbCr & "Pick second slice point: ")
.InitializeUserInput 1
varPnt3 = .GetPoint(varPnt2, vbCr & "Pick last slice point: ")
'' section the solid
Set objNew = objFirst.SliceSolid(varPnt1, varPnt2, varPnt3, True)
If objNew Is Nothing Then
MsgBox "Couldn't slice using those points"
Else
'' highlight new solid
objNew.Highlight False
objNew.Color = objNew.Color + 1
objNew.Update
'' move section region to new location
.InitializeUserInput 1
varPnt2 = .GetPoint(varPnt1, vbCr & "Pick a new location: ")
objNew.Move varPnt1, varPnt2
End If
End With
'' shade the view
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestSectionSolid()
Dim objFirst As Acad3DSolid
Dim objSecond As Acad3DSolid
Dim objNew As AcadRegion
Dim varPick As Variant
Dim varPnt1 As Variant
Dim varPnt2 As Variant
Dim varPnt3 As Variant
On Error Resume Next
With ThisDrawing.Utility
'' get first solid from user
.GetEntity objFirst, varPick, vbCr & "Pick a solid to section: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
'' highlight entity
objFirst.Highlight True
objFirst.Update
.InitializeUserInput 1
varPnt1 = .GetPoint(varPick, vbCr & "Pick first section point: ")
.InitializeUserInput 1
varPnt2 = .GetPoint(varPnt1, vbCr & "Pick second section point: ")
.InitializeUserInput 1
varPnt3 = .GetPoint(varPnt2, vbCr & "Pick last section point: ")
'' section the solid
Set objNew = objFirst.SectionSolid(varPnt1, varPnt2, varPnt3)
If objNew Is Nothing Then
MsgBox "Couldn't section using those points"
Else
'' highlight new solid
objNew.Highlight False
objNew.Color = acWhite
objNew.Update
'' move section region to new location
.InitializeUserInput 1
varPnt2 = .GetPoint(varPnt1, vbCr & "Pick a new location: ")
objNew.Move varPnt1, varPnt2
End If
'' dehighlight entities
objFirst.Highlight False
objFirst.Update
End With
'' shade the view
ThisDrawing.SendCommand "_shade" & vbCr
End Sub
Public Sub TestMassProperties()
Dim objEnt As Acad3DSolid
Dim varPick As Variant
Dim strMassProperties As String
Dim varProperty As Variant
Dim intI As Integer
On Error Resume Next
'' let user pick a solid
With ThisDrawing.Utility
.GetEntity objEnt, varPick, vbCr & "Pick a solid: "
If Err Then
MsgBox "That is not an Acad3DSolid"
Exit Sub
End If
End With
'' format mass properties
With objEnt
strMassProperties = "Volume: "
strMassProperties = strMassProperties & vbCr & " " & .Volume
strMassProperties = strMassProperties & vbCr & vbCr & _
"Center Of Gravity: "
For Each varProperty In .Centroid
strMassProperties = strMassProperties & vbCr & " "_
& varProperty
Next
strMassProperties = strMassProperties & vbCr & vbCr & _
"Moment Of Inertia: "
For Each varProperty In .MomentOfInertia
strMassProperties = strMassProperties & vbCr & " " & _
varProperty
Next
strMassProperties = strMassProperties & vbCr & vbCr & _
"Product Of Inertia: "
For Each varProperty In .ProductOfInertia
strMassProperties = strMassProperties & vbCr & " " & _
varProperty
Next
strMassProperties = strMassProperties & vbCr & vbCr & _
"Principal Moments: "
For Each varProperty In .PrincipalMoments
strMassProperties = strMassProperties & vbCr & " " & _
varProperty
Next
strMassProperties = strMassProperties & vbCr & vbCr & _
"Radii Of Gyration: "
For Each varProperty In .RadiiOfGyration
strMassProperties = strMassProperties & vbCr & " " & _
varProperty
Next
strMassProperties = strMassProperties & vbCr & vbCr & _
"Principal Directions: "
For intI = 0 To UBound(.PrincipalDirections) / 3
strMassProperties = strMassProperties & vbCr & " (" & _
.PrincipalDirections((intI - 1) * 3) & ", " & _
.PrincipalDirections((intI - 1) * 3 + 1) & "," & _
.PrincipalDirections((intI - 1) * 3 + 2) & ")"
Next
End With
'' highlight entity
objEnt.Highlight True
objEnt.Update
'' display properties
MsgBox strMassProperties, , "Mass Properties"
'' dehighlight entity
objEnt.Highlight False
objEnt.Update
End Sub