Hello Everyone,
I have the following function (MeasurePointDelta). It reports the distance (either x, y, or z) between two sketch points. It functions correctly, however, the selection of the points takes forever. I call this function probably 30 or 40 times from another sub and the sub takes 5 or 6 seconds to run. That's not long, however, in the near future I will be calling this routine hundreds and hundreds of times.
I'm wondering if there is a way to accomplish the same thing without selecting the points. In this thread Karl-Gustav Johansson alludes to being able to pass the CreateMeasure method an array so no occurs. I can't figure out how to do this. Is it possible? Is there another way? Any help would be much appreciated.
Thanks
Kyle
Sub ExampleCall()
Dim s1 As String, s2 As String
s1 = "Point4@Sketch1@Pendant01-2@Config001"
s2 = "Point64@Sketch1@Lower01-1@Config001"
Debug.Print MeasurePointDelta(s1, s2, "X")
End Sub
Function MeasurePointDelta(sID1 As String, sID2 As String, sDir As String)
Dim oMeasure As Object, bStatus As Boolean
Dim X1 As Double, Y1 As Double, Z1 As Double, X2 As Double, Y2 As Double, Z2 As Double
'Point 1
bStatus = swPart.Extension.SelectByID2(sID1, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
Set oMeasure = swPart.Extension.CreateMeasure
bStatus = oMeasure.Calculate(Nothing)
X1 = oMeasure.x
Y1 = oMeasure.Y
Z1 = oMeasure.Z
'Point 2
bStatus = swPart.Extension.SelectByID2(sID2, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
Set oMeasure = swPart.Extension.CreateMeasure
bStatus = oMeasure.Calculate(Nothing)
X2 = oMeasure.x
Y2 = oMeasure.Y
Z2 = oMeasure.Z
swPart.ClearSelection2 True
'Dist b/t points
Select Case sDir
Case "X"
MeasurePointDelta = X2 - X1
Case "Y"
MeasurePointDelta = Y2 - Y1
Case "Z"
MeasurePointDelta = Z2 - Z1
End Select
End Function
SolidworksApi macros