Set Tangent Vectors for Sketch Points Example (VBA)
This example shows how to set the tangent vectors for sketch points
in a spline.
'----------------------------------------------------------
'
' Preconditions:
' (1)
Sketch of spline is open.
' (2)
A frame point exists in the sketch.
'
' Postconditions: Tangent vectors are set for the sketch
points of the spline.
'
'-----------------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSketch As
SldWorks.sketch
Dim
vSkPtArr As
Variant
Dim
vSkPt As
Variant
Dim
swSkPt As
SldWorks.SketchPoint
Dim
vTangent As
Variant
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSketch = swModel.GetActiveSketch2
vSkPtArr
= swSketch.GetSketchPoints
For
Each vSkPt In vSkPtArr
Set
swSkPt = vSkPt
vTangent
= swSkPt.GetFramePointTangent(bRet)
'
Positions before adjusting spline tangency
If
bRet Then
Debug.Print
" Pt
[" & swSkPt.GetId(0)
& ", " & swSkPt.GetId(1)
& "]"
Debug.Print
" Pos
=
(" & swSkPt.x * 1000#
& ", " & swSkPt.y
* 1000# & ", " & swSkPt.z
* 1000# & ") mm"
End
If
Next
vSkPt
For
Each vSkPt In vSkPtArr
Set
swSkPt = vSkPt
vTangent
= swSkPt.GetFramePointTangent(bRet)
'
Positions after adjusting spline tangency
If
bRet Then
Debug.Print
" Pt
[" & swSkPt.GetId(0)
& ", " & swSkPt.GetId(1)
& "]"
Debug.Print
" Pos
=
(" & swSkPt.x * 1000#
& ", " & swSkPt.y
* 1000# & ", " & swSkPt.z
* 1000# & ") mm"
Debug.Print
" Old
tangent
= (" & vTangent(0) & ", " & vTangent(1) &
")"
vTangent(0)
= vTangent(0) + 0.01
vTangent(1)
= vTangent(1) + 0.01
Debug.Print
" New1
tangent = (" & vTangent(0) & ", " & vTangent(1)
& ")"
bRet
= swSkPt.SetFramePointTangent((vTangent))
vTangent
= swSkPt.GetFramePointTangent(bRet)
Debug.Print
" Pos
=
(" & swSkPt.x * 1000#
& ", " & swSkPt.y
* 1000# & ", " & swSkPt.z
* 1000# & ") mm"
Debug.Print
" New2
tangent = (" & vTangent(0) & ", " & vTangent(1)
& ")"
End
If
Next
vSkPt
End Sub
'------------------------------------