.NET

.NET

Reply
luc
Member
luc
Posts: 5
Registered: ‎11-24-2013
Message 1 of 4 (400 Views)
Accepted Solution

intersectwith between polyline and lines problem

400 Views, 3 Replies
11-25-2013 12:20 AM

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 2 of 4 (389 Views)

Re: intersectwith between polyline and lines problem

11-25-2013 02:12 AM in reply to: luc

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. :smileywink:

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (374 Views)

Re: intersectwith between polyline and lines problem

11-25-2013 06:12 AM in reply to: luc

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
luc
Member
luc
Posts: 5
Registered: ‎11-24-2013
Message 4 of 4 (347 Views)

Re: intersectwith between polyline and lines problem

11-25-2013 11:50 PM in reply to: Alfred.NESWADBA
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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.