Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 1 of 3

How to change a polyline shape if it intersect with another

198 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
716 Posts
4 Kudos
Registered: ‎01-24-2003
Post 2 of 3

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*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 3 of 3

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




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!