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

How to change a polyline shape if it intersect with another

2 REPLIES 2
Reply
Message 1 of 3
yaqiz
387 Views, 2 Replies

How to change a polyline shape if it intersect with another

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

2 REPLIES 2
Message 2 of 3
Ed.Jobe
in reply to: yaqiz

Here's a start.

Ed

EESignature

Message 3 of 3
Hallex
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

                    Return
                End If

                If result.Value.Count <> 2 Then

                    Return

                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

                    Return

                End If

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

                Dim pline2 As Polyline = TryCast(obj, Polyline)

                If pline2 Is Nothing Then

                    Return

                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")

                    Return

                End If

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

                objArray1.Add(pline1)

                ' 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()

                objArray2.Add(pline2)

                ' 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)

                    objreg2.Dispose()

                    ' Add the final region to the database

                    btr.AppendEntity(objreg1)

                    tr.AddNewlyCreatedDBObject(objreg1, True)

                    objreg1.ColorIndex = 1

                Else

                    ' Subtract the smaller region from the larger one

                    objreg2.BooleanOperation(BooleanOperationType.BoolSubtract, objreg1)

                    objreg1.Dispose()

                    ' Add the final region to the database

                    btr.AppendEntity(objreg2)

                    tr.AddNewlyCreatedDBObject(objreg2, True)

                    objreg2.ColorIndex = 1

                End If

                tr.Commit()

            End Using

        End Sub

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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