intersectwith between polyline and lines problem

intersectwith between polyline and lines problem

Anonymous
Not applicable
2,528 Views
3 Replies
Message 1 of 4

intersectwith between polyline and lines problem

Anonymous
Not applicable

Hi ,

 

I have a problem while executing intersectwith between polylines and lines

 

the polyline execute intersectwith method referencing a line object with expandboth parameter value

but sometimes , the intersection is not found

 

when using expandthis or expandargument values, I have no problems

 

I'am using VS2012 express and Autocad 2014

 

the attached project containt :

  an image (result;png) showing my result

  a dwg file (dessin3.dwg) , it is my test file

  the source code for testing , (test" command)

      it find all polylines and all lines in the drawing , compute the intersections between each couple and draw a dbpoint on each

 

can you help me ?

 

thanks

 

Regards

 

Luc

0 Likes
Accepted solutions (1)
2,529 Views
3 Replies
Replies (3)
Message 2 of 4

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

start command _UNITS and set the number of decimal placed for "Length" ==> "Precision" to the maximum.

Then select the lowest red line and look to the Z-values for start- and endpoint.

 

2013-11-25 11-10-14.png

Having different Z-values ends most of the time in problems. 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 4

Hallex
Advisor
Advisor

Luc,

Try this code instead

        <CommandMethod("test3")> _
        Public Shared Sub test3()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim Ed As Editor = doc.Editor

            Dim FilterList(0) As TypedValue
            FilterList.SetValue(New TypedValue(DxfCode.Start, "*POLYLINE"), 0)
            Dim Filtre As New SelectionFilter(FilterList)
            Dim Sel As PromptSelectionResult = Ed.SelectAll(Filtre)
            Dim IdsPoly() As ObjectId = Sel.Value.GetObjectIds

            Dim FilterList2(0) As TypedValue
            FilterList2.SetValue(New TypedValue(DxfCode.Start, "LINE"), 0)
            Dim Filtre2 As New SelectionFilter(FilterList2)
            Sel = Ed.SelectAll(Filtre2)
            Dim IdsLine() As ObjectId = Sel.Value.GetObjectIds


            Using TR As Transaction = db.TransactionManager.StartTransaction
                Dim ModelSpaceId As ObjectId = SymbolUtilityServices.GetBlockModelSpaceId(db)
                Dim btr As BlockTableRecord = TR.GetObject(ModelSpaceId, OpenMode.ForWrite)

                For P = LBound(IdsPoly) To UBound(IdsPoly)
                    Dim Idpoly As ObjectId = IdsPoly(P)
                    Dim Poly As Polyline = TR.GetObject(Idpoly, OpenMode.ForRead)
                    For L = LBound(IdsLine) To UBound(IdsLine)
                        Dim id As ObjectId = IdsLine(L)
                        Dim pts As New Point3dCollection
                        Dim Lig As Autodesk.AutoCAD.DatabaseServices.Line = CType(TR.GetObject(id, OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.Line)
                        'assuming just extend lines to get intersection
                        Lig.IntersectWith(Poly, Intersect.ExtendThis, pts, IntPtr.Zero, IntPtr.Zero)
                        For Each Pt As Point3d In pts
                            'original code commented :
                            'Dim d As New DBPoint
                            'd.SetDatabaseDefaults()
                            'd.Position = Pt
                            'btr.AppendEntity(d)
                            'TR.AddNewlyCreatedDBObject(d, True)
                            Dim c As Circle = New Circle(Pt, Vector3d.ZAxis, 15)
                            c.ColorIndex = 1
                            btr.AppendEntity(c)
                            TR.AddNewlyCreatedDBObject(c, True)
                        Next
                    Next
                Next
                TR.Commit()
            End Using

        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi Alfred

You're right, the Z coordinate is the problem.

the mistake is why sometimes the intersection is found and sometime not

regards

Luc
0 Likes