Valued Contributor
Posts: 86
Registered: ‎07-14-2010
Message 1 of 3 (195 Views)

How to change a polyline shape if it intersect with another

195 Views, 2 Replies
06-21-2012 08:45 AM

Hi Guys,


I have 2 polyline. First I need to know whether those 2 polyline intersect with each other or not. If they are I need to change one of the polyline shape deduct the intersection area.


How can I do that?


Thanks very much

Distinguished Contributor
Posts: 704
Registered: ‎01-24-2003
Message 2 of 3 (190 Views)

Re: How to change a polyline shape if it intersect with another

06-21-2012 09:39 AM in reply to: yaqiz

Here's a start.

*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 3 (176 Views)

Re: How to change a polyline shape if it intersect with another

06-21-2012 01:22 PM in reply to: yaqiz

Here is a start too

        <CommandMethod("Remarea")> _
        Public Shared Sub DeductPolyline()

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim db As Database = doc.Database

            'start a transaction
            Using tr As Transaction = db.TransactionManager.StartTransaction()

                Dim tvs As TypedValue() = New TypedValue() {New TypedValue(0, "lwpolyline"), New TypedValue(70, 1)}

                Dim filter As New SelectionFilter(tvs)

                Dim pso As New PromptSelectionOptions()

                pso.MessageForRemoval = vbLf & "Select 2 closed polylines only: "

                pso.MessageForAdding = vbLf & "Select 2 closed polylines: "

                Dim result As PromptSelectionResult = ed.GetSelection(filter)

                If result.Status <> PromptStatus.OK Then

                End If

                If result.Value.Count <> 2 Then


                End If

                Dim sset As SelectionSet = result.Value

                Dim ids As ObjectId() = sset.GetObjectIds()

                Dim obj As DBObject = TryCast(tr.GetObject(ids(0), OpenMode.ForRead), DBObject)

                Dim pline1 As Polyline = TryCast(obj, Polyline)

                If pline1 Is Nothing Then


                End If

                obj = TryCast(tr.GetObject(ids(1), OpenMode.ForRead), DBObject)

                Dim pline2 As Polyline = TryCast(obj, Polyline)

                If pline2 Is Nothing Then


                End If

                Dim pts As New Point3dCollection()

                pline1.IntersectWith(pline2, Intersect.OnBothOperands, pts, CInt(IntPtr.Zero), CInt(IntPtr.Zero))

                If pts.Count = 0 Then

                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Polylines doesn't intersects each other, Exit")


                End If

                ' add the polylines to the array
                Dim objArray1 As New DBObjectCollection()


                ' create the 1 st region
                Dim objreg1 As New Region()

                Dim objRegions1 As New DBObjectCollection()

                objRegions1 = Region.CreateFromCurves(objArray1)

                objreg1 = TryCast(objRegions1(0), Region)

                Dim objArray2 As New DBObjectCollection()


                ' create the 2nd region
                Dim objreg2 As New Region()

                Dim objRegions2 As New DBObjectCollection()

                objRegions2 = Region.CreateFromCurves(objArray2)

                objreg2 = TryCast(objRegions2(0), Region)

                Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False), BlockTableRecord)

                ' Subtract region 1 from region 2
                If objreg1.Area > objreg2.Area Then
                    ' Subtract the smaller region from the larger one

                    objreg1.BooleanOperation(BooleanOperationType.BoolSubtract, objreg2)


                    ' Add the final region to the database


                    tr.AddNewlyCreatedDBObject(objreg1, True)

                    objreg1.ColorIndex = 1


                    ' Subtract the smaller region from the larger one

                    objreg2.BooleanOperation(BooleanOperationType.BoolSubtract, objreg1)


                    ' Add the final region to the database


                    tr.AddNewlyCreatedDBObject(objreg2, True)

                    objreg2.ColorIndex = 1

                End If


            End Using

        End Sub




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.