Get Intersecting Face and Edge Example (VBA)
This example shows how to get the intersection of a face and an edge.
'----------------------------------------------
'
' Problem:
' A
face and an edge intersect in a series of points.
'
' This
code shows how to use some of the geometry-related and
' topology-related
APIs to get the intersection points.
'
' Preconditions:
' (1)
Part of assembly is open.
' (2)
Assembly is fully resolved.
' (3)
Two items are selected in the graphics window.
' (4)
Face is the first selected item.
' (5)
Edge is the second selected item.
' (6)
Face and the edge intersect.
'
' Postconditions:3D sketch is inserted with sketch points
located
' at
the intersection of the face and the edge.
'
'-----------------------------------------------
Option Explicit
Sub CreatePoints _
( _
swApp
As SldWorks.SldWorks, _
swModel
As SldWorks.ModelDoc2, _
vPtArray
As Variant _
)
Dim
swSketchPt As
SldWorks.SketchPoint
Dim
bRet As
Boolean
Dim
i As
Long
swModel.SetAddToDB True
swModel.Insert3DSketch2 False
For
i = 0 To UBound(vPtArray) Step 3
Set
swSketchPt = swModel.CreatePoint2(vPtArray(i
+ 0), vPtArray(i + 1), vPtArray(i + 2))
Next
i
swModel.SetAddToDB False
swModel.Insert3DSketch2 True
bRet
= swModel.EditRebuild3
Debug.Assert
bRet
End Sub
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swFace As
SldWorks.face2
Dim
swSurf As
SldWorks.surface
Dim
swEdge As
SldWorks.Edge
Dim
swCurve As
SldWorks.curve
Dim
vPointArray As
Variant
Dim
vTArray As
Variant
Dim
vUVArray As
Variant
Dim
vCurveParam As
Variant
Dim
vCurveBounds As
Variant
Dim
nCurveBounds(0 To 5) As
Double
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = CreateObject("SldWorks.Application")
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swFace = swSelMgr.GetSelectedObject5(1)
Set
swEdge = swSelMgr.GetSelectedObject5(2)
Set
swSurf = swFace.GetSurface
Set
swCurve = swEdge.GetCurve
vCurveParam
= swEdge.GetCurveParams2
For
i = 0 To 5
nCurveBounds(i)
= vCurveParam(i)
Next
i
vCurveBounds
= nCurveBounds
bRet
= swSurf.IntersectCurve(swCurve,
(vCurveBounds), vPointArray, vTArray, vUVArray)
Debug.Assert
bRet
CreatePoints
swApp, swModel, vPointArray
End Sub
'------------------------------------------------