IntersectWith method example

Sub IntersectWith_Example()
'This example adds an LWpolyline and a Line entity to the
'ModelSpace. It then finds the intersection points between
'these entities using the IntersectWith method.
    Dim plVertices(0 To 15) As Double
    plVertices(0) = 1: plVertices(1) = 0
    plVertices(2) = 1: plVertices(3) = 1
    plVertices(4) = 2: plVertices(5) = 1
    plVertices(6) = 2: plVertices(7) = 0
    plVertices(8) = 3: plVertices(9) = 0
    plVertices(10) = 3: plVertices(11) = 1
    plVertices(12) = 4: plVertices(13) = 1
    plVertices(14) = 4: plVertices(15) = 0
    Dim oPline As AcadLWPolyline
    Set oPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(plVertices)
    Dim oLine As AcadLine
    Dim oPt1(0 To 2) As Double: oPt1(0) = 0: oPt1(1) = 1: oPt1(2) = 0
    Dim oPt2(0 To 2) As Double: oPt2(0) = 5: oPt2(1) = 0: oPt2(2) = 0
    Set oLine = ThisDrawing.ModelSpace.AddLine(oPt1, oPt2)
    
    ' Find the intersection points between the polyline and the line
    Dim vPoints As Variant
    vPoints = oPline.IntersectWith(oLine, acExtendNone)
    infoIntersections vPoints
End Sub
Private Sub infoIntersections(inPoints As Variant)
    Dim i As Integer
    Dim n As Integer
    Dim sBuf As String
    If VarType(inPoints) <> vbEmpty Then
        For i = LBound(inPoints) To UBound(inPoints) Step 3
            n = n + 1
            sBuf = "Intersection Point" & n & " is: ( " & inPoints(i) & ", " & inPoints(i + 1) & ", " & inPoints(i + 2) & ")"
            MsgBox sBuf, , "IntersectWith Example"
            sBuf = vbNullString
        Next
    End If
End Sub

© Bricsys NV. All rights reserved.