IntersectWith troubles

IntersectWith troubles

Anonymous
Not applicable
821 Views
2 Replies
Message 1 of 3

IntersectWith troubles

Anonymous
Not applicable

Hi everyone, having trouble when using InsersectWith on a polyline to check if a line definited by 2 points would intersect with it. Currently I am geting an "eInvalidInput" error whenever the IntersectWith method is called. Any help would be greatly appreciated. Code below:

 

    Public Function checkIntersect(ByVal pt1 As Point3d, ByVal pt2 As Point3d) As Boolean
        Dim line As Line = New Line(pt1, pt2)
        Dim plane As New Plane(Point3d.Origin, ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis)
        Dim pts As Point3dCollection = New Point3dCollection
            Dim filterList(3) As TypedValue
            filterList.SetValue(New TypedValue(DxfCode.Operator, "<and"), 0)
            filterList.SetValue(New TypedValue(DxfCode.Start, "LWPOLYLINE"), 1)
            filterList.SetValue(New TypedValue(DxfCode.LayerName, areaLayersArray(i)), 2)
            filterList.SetValue(New TypedValue(DxfCode.Operator, "and>"), 3)
            Dim filter As New SelectionFilter(filterList)
            Dim res As PromptSelectionResult = ed.SelectAll(filter)
            If res.Status = PromptStatus.OK Then
                Dim oset As SelectionSet = res.Value
                Dim objIDs() As ObjectId = oset.GetObjectIds
                Using tr As Transaction = db.TransactionManager.StartTransaction()
                    For Each acObjId As ObjectId In objIDs
                        Dim polyLine As Polyline = CType(tr.GetObject(acObjId, OpenMode.ForRead), Polyline)
                        Dim entity As Entity = CType(line, Entity)
                        polyLine.IntersectWith(entity, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero)
                    Next
                    tr.Commit()
                End Using
            End If
        If pts.Count = 0 Then
            Return False
        Else
            Return True
        End If
    End Function

 

 

0 Likes
Accepted solutions (1)
822 Views
2 Replies
Replies (2)
Message 2 of 3

hgasty1001
Advisor
Advisor
Accepted solution

Hi,

 

I'm not sure, but if the "line" was not added to the database, I think the intersect with will fail, also I'm not sure the point about casting to entity of that line. 2 alternatives, if you only want to check if some polyline intersect a line, you can try with a "fence" filter, if the selection set has elements, then return true, else false. As for testing using intersectwith method, it's better to use a non database resident object like linesegment3d, that it's easely created with dim lsegment3d as linesegment3d= new linesegment3d(startpoint,endpoint) and that's it, now you can test the intersection with the polyline against the segment without creating a resident object like line.

 

Gaston Nunez

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks Gaston. I've got it working by creating a line segment and testing for an intersection with each segment of the polyline.

0 Likes