.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IntersectWith troubles

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
582 Views, 2 Replies

IntersectWith troubles

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

 

 

2 REPLIES 2
Message 2 of 3
hgasty1001
in reply to: Anonymous

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

Message 3 of 3
Anonymous
in reply to: hgasty1001

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost