Intersectwith - VBA- AutoCAD

Intersectwith - VBA- AutoCAD

Ray-Sync
Advocate Advocate
971 Views
1 Reply
Message 1 of 2

Intersectwith - VBA- AutoCAD

Ray-Sync
Advocate
Advocate

Hi,
I have this:

RaySync_1-1685656254353.png

I got this code:

Private Sub CommandButton1_Click()
    Dim Sset As AcadSelectionSet
    Dim filterType(0) As Integer, i As Integer
    Dim filterData(0) As Variant
    Dim PL() As AcadLWPolyline
    Dim intersectionCount As Integer

    filterType(0) = 8: filterData(0) = "COLUMN"

    Set Sset = ThisDrawing.SelectionSets.Add("Be")
    Sset.Select acSelectionSetAll, , , filterType, filterData

    ReDim PL(Sset.Count - 1)

    For i = 0 To Sset.Count - 1
        Set PL(i) = Sset.Item(i)
    Next i

    If PL(0).IntersectWith(PL(1), acExtendNone) Is Nothing Then
        
    Else
        PL(1).Delete
    End If

    Sset.Delete
End Sub

But I have a problem there:

RaySync_2-1685656420133.pngRaySync_3-1685656442465.png

 

The code doesn't work. Can you help me?

jefferson
0 Likes
Accepted solutions (1)
972 Views
1 Reply
Reply (1)
Message 2 of 2

Ed__Jobe
Mentor
Mentor
Accepted solution

The IntersectWith method doesn't return an Object, so you can't check if it is Nothing. It returns an array of doubles representing the intersection points. x and y. Your If statement could check if the UBOUND of the array is 0.

 

Note that even if you solve this error, your logic may still not find any intersections at all. For example, suppose that PL(0) is one of the rectangles that don't intersect with anything. Maybe a better approach would be to prompt the user to select polyline1 and then polyline2.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature