Get Start and End Points of Spline Example (VBA)
This example shows how to get the start and end points of a spline.
'-------------------------------------------------
'
' Preconditions:
' (1)
Sketch is active.
' (2)
Spline is selected.
'
' Postconditions: None
'
'--------------------------------------------------
Option Explicit
Public Enum swSketchSegments_e
swSketchLINE
= 0
swSketchARC
= 1
swSketchELLIPSE
= 2
swSketchSPLINE
= 3
swSketchTEXT
= 4
swSketchPARABOLA
= 5
End Enum
' Define two types
Type DoubleRec
dValue
As Double
End Type
Type Long2Rec
iLower
As Long
iUpper
As Long
End Type
' Extract two integer values from a single double value
' by assigning a DoubleRec to the double value,
' copying the value to a Long2Rec, and
' extracting the integer values
Function ExtractFields _
( _
ByVal
dValue As Double, _
iLower
As Long, _
iUpper
As Long _
)
Dim
dr As
DoubleRec
Dim
i2r As
Long2Rec
'
Set the double value
dr.dValue
= dValue
'
Copy the values
LSet
i2r = dr
'
Extract the values
iLower
= i2r.iLower
iUpper
= i2r.iUpper
End Function
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swSketchSeg As
SldWorks.SketchSegment
Dim
swCurve As
SldWorks.Curve
Dim
nStartParam As
Double
Dim
nEndParam As
Double
Dim
bIsClosed As
Boolean
Dim
bIsPeriodic As
Boolean
Dim
vStart As
Variant
Dim
vEnd As
Variant
Dim
nDummy As
Long
Dim
nStartSuccess As
Long
Dim
nEndSuccess As
Long
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swSketchSeg = swSelMgr.GetSelectedObject5(1)
Set
swCurve = swSketchSeg.GetCurve
bRet
= swCurve.GetEndParams(nStartParam,
nEndParam, bIsClosed, bIsPeriodic)
Debug.Assert
bRet
vStart
= swCurve.Evaluate(nStartParam)
vEnd
= swCurve.Evaluate(nEndParam)
ExtractFields
vStart(6), nStartSuccess, nDummy
ExtractFields
vEnd(6), nEndSuccess, nDummy
Debug.Assert
nStartSuccess
Debug.Assert
nEndSuccess
Debug.Print
"Length = " & swCurve.GetLength2(nStartParam,
nEndParam) * 1000# & " mm"
Debug.Print
" Start
Pt =
(" & vStart(0) * 1000# & ", " & vStart(1) *
1000# & ", " & vStart(2) * 1000# & ") mm"
Debug.Print
" tangent
=
(" & vStart(3) & ", " & vStart(4) & ",
" & vStart(5) & ")"
Debug.Print
" End
Pt
=
(" & vEnd(0) * 1000# & ", " & vEnd(1) * 1000#
& ", " & vEnd(2) * 1000# & ") mm"
Debug.Print
" tangent
=
(" & vEnd(3) & ", " & vEnd(4) & ",
" & vEnd(5) & ")"
End Sub