Get Reference Curve Information Example (VBA)
This example shows how to get information about a reference curve (for
example, a projected curve) through a set of points.
'------------------------------------------
'
' Preconditions:
' (1)
Part or assembly is open.
' (2)
Reference curve is selected in the FeatureManager design tree.
' This
code does not work if the reference curve is selected
' in
the graphics area.
'
' Postconditions: None
'
'------------------------------------------
Option Explicit
Function TessLength _
( _
vTessPts
As Variant _
) As Double
Dim
i As
Long
For
i = 0 To ((UBound(vTessPts) + 1) / 3 - 2)
TessLength
= TessLength + _
Sqr(
_
(vTessPts(3
* i + 0) - vTessPts(3 * i + 3)) ^ 2# + _
(vTessPts(3
* i + 1) - vTessPts(3 * i + 4)) ^ 2# + _
(vTessPts(3
* i + 2) - vTessPts(3 * i + 5)) ^ 2# _
)
Next
i
End Function
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swFeat As
SldWorks.feature
Dim
swRefCurve As
SldWorks.ReferenceCurve
Dim
swEdge As
SldWorks.Edge
Dim
swCurve As
SldWorks.curve
Dim
vCurveParam As
Variant
Dim
nStartPt(2) As
Double
Dim
nEndPt(2) As
Double
Dim
vStartPt As
Variant
Dim
vEndPt As
Variant
Dim
vTessPts As
Variant
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swFeat = swSelMgr.GetSelectedObject5(1)
Set
swRefCurve = swFeat.GetSpecificFeature
Set
swEdge = swRefCurve.GetFirstSegment
Debug.Print
"Feat = " & swFeat.Name
While
Not swEdge Is Nothing
Set
swCurve = swEdge.GetCurve
vCurveParam
= swEdge.GetCurveParams2
nStartPt(0)
= vCurveParam(0)
nStartPt(1)
= vCurveParam(1)
nStartPt(2)
= vCurveParam(2)
nEndPt(0)
= vCurveParam(3)
nEndPt(1)
= vCurveParam(4)
nEndPt(2)
= vCurveParam(5)
vStartPt
= nStartPt
vEndPt
= nEndPt
vTessPts
= swCurve.GetTessPts(0.000001,
0.000001, (vStartPt), (vEndPt))
Debug.Print
" Curve("
& i & ")"
Debug.Print
" Start
= ("
& vCurveParam(0) * 1000# & ", " & vCurveParam(1)
* 1000# & ", " & vCurveParam(2) * 1000# & ")
mm"
Debug.Print
" End
=
(" & vCurveParam(3) * 1000# & ", " & vCurveParam(4)
* 1000# & ", " & vCurveParam(5) * 1000# & ")
mm"
Debug.Print
" Length
= " & swCurve.GetLength2(vCurveParam(6),
vCurveParam(7)) * 1000# & " mm"
Debug.Print
" TessLength("
& UBound(vTessPts) & ") =
" & TessLength(vTessPts) * 1000# & " mm"
i
= i + 1
Set
swEdge = swRefCurve.GetNextSegment
Wend
End Sub
'------------------------------------------