Measure Selected Entities Example (VBA)
This example shows how to use the IMeasure APIs.
'****************************************************
'
' Preconditions: Model document is open and measurable
objects
' are
selected.
'
' Postconditions: None.
'
'****************************************************
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim Measure As Measure
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set Measure = Part.Extension.CreateMeasure
Measure.ArcOption
= 0 'Can
set this to 0, 1, or 2
'
0 - Center to Center
'
1 - Minimum Distance
'
2 - Maximum Distance
Dim strDisplay As String
boolstatus = Measure.Calculate(Nothing)
If (boolstatus) Then
If
(Not (Measure.Length = -1)) Then
Debug.Print
"Length: " & Measure.Length
End
If
If
(Not (Measure.Area = -1)) Then
Debug.Print
"Area: " & Measure.Area
End
If
If
(Not (Measure.ArcLength = -1))
Then
Debug.Print
"Arc length: " & Measure.ArcLength
End
If
If
(Not (Measure.ChordLength = -1))
Then
Debug.Print
"Chord length: " & Measure.ChordLength
End
If
If
(Not (Measure.Diameter = -1))
Then
Debug.Print
"Diameter: " & Measure.Diameter
End
If
If
(Not (Measure.Radius = -1)) Then
Debug.Print
"Radius: " & Measure.Radius
End
If
If
(Not (Measure.Perimeter = -1))
Then
Debug.Print
"Perimeter: " & Measure.Perimeter
End
If
If
(Not (Measure.X = -1)) Then
Debug.Print
"X coordinate: " & Measure.X
End
If
If
(Not (Measure.Y = -1)) Then
Debug.Print
"Y coordinate: " & Measure.Y
End
If
If
(Not (Measure.Z = -1)) Then
Debug.Print
"Z coordinate: " & Measure.Z
End
If
If
(Not (Measure.DeltaX = -1)) Then
Debug.Print
"DeltaX: " & Measure.DeltaX
End
If
If
(Not (Measure.DeltaY = -1)) Then
Debug.Print
"DeltaY: " & Measure.DeltaY
End
If
If
(Not (Measure.DeltaZ = -1)) Then
Debug.Print
"DeltaZ: " & Measure.DeltaZ
End
If
If
(Not (Measure.Angle = -1)) Then
Debug.Print
"Angle: " & Measure.Angle
End
If
If
(Not (Measure.CenterDistance =
-1)) Then
Debug.Print
"Center distance: " & Measure.CenterDistance
End
If
If
(Not (Measure.NormalDistance =
-1)) Then
Debug.Print
"Normal distance: " & Measure.NormalDistance
End
If
If
(Not (Measure.Distance = -1))
Then
Debug.Print
"Distance: " & Measure.Distance
End
If
If
(Not (Measure.TotalLength = -1))
Then
Debug.Print
"Total length: " & Measure.TotalLength
End
If
If
(Not (Measure.TotalArea = -1))
Then
Debug.Print
"Total Area : " & Measure.TotalArea
End
If
If
(Measure.IsParallel) Then
Debug.Print
"IsParallel : " & Measure.IsParallel
End
If
If
(Measure.IsIntersect) Then
Debug.Print
"Is Intersect : " & Measure.IsIntersect
End
If
If
(Measure.IsPerpendicular = -1)
Then
Debug.Print
"Is Perpendicular : " & Measure.IsPerpendicular
End
If
If
(Not (Measure.Projection = -1))
Then
Debug.Print
"Projection : " & Measure.Projection
End
If
If
(Not (Measure.Normal = -1)) Then
Debug.Print
"Normal : " & Measure.Normal
End
If
If
(Not (Measure.SpericalCenterDistance
= -1)) Then
Debug.Print
"Sperical Center Distance : " & Measure.SpericalCenterDistance
End
If
If
(Measure.IsConcentricSpheres)
Then
Debug.Print
"Is Concentric Spheres : " & Measure.IsConcentricSpheres
End
If
Else
Debug.Print
"Invalid combination of selected entities."
End If
End Sub