How to reverse polyline direction programmatically vb.net

hi!

i just want to know how to reverse the direction of polylines:  LWPolyline, Polyline2D and 3D polyline programmatically using vb.net.
i tried using the ReverseCurve but the problem the selected polyline did not change its direction.
below are the codes i tried. please let me know what did i missed. thank you very much.

_
        Public Shared Sub ReversePL()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim per As PromptEntityResult = ed.GetEntity("Select a polyline")

            If per.Status <> PromptStatus.OK Then Exit Sub

            Using tr As Transaction = db.TransactionManager.StartTransaction
                Dim obj As DBObject = tr.GetObject(per.ObjectId, OpenMode.ForWrite)

                'if a "lightweight" (or optimized) polyline
                Dim lwp As Polyline = TryCast(obj, Polyline)
                If lwp IsNot Nothing Then

                    lwp.ReverseCurve()                    
                Else
                    'if an old-style, 2D polyline
                    Dim p2d As Polyline2d = TryCast(obj, Polyline2d)
                    If p2d IsNot Nothing Then
                        p2d.ReverseCurve()                        
                    Else
                        'if an old-style, 3D polyline
                        Dim p3d As Polyline3d = TryCast(obj, Polyline3d)

                        If p3d IsNot Nothing Then
                            p3d.ReverseCurve()                           
                        End If
                    End If
                End If
                tr.Commit()
            End Using
        End Sub

Comments

  • your right, the method seem so have no effect, you might be able to do something long hand I.e.

    [code]

           if (lwp != null)

            {

              Polyline pline = new Polyline(lwp.NumberOfVertices);

              pline.SetPropertiesFrom(lwp);

              for (int i = 0, j = lwp.NumberOfVertices - 1; i < lwp.NumberOfVertices; j--, i++)

              {

                pline.AddVertexAt(i,

                  lwp.GetPoint2dAt(j),

                  lwp.GetBulgeAt(j),

                  lwp.GetStartWidthAt(j),

                  lwp.GetEndWidthAt(j));

              }

              lwp.HandOverTo(pline, true, true);

            }

    [/code]

  • Daniel,

    Thank you for the reply.  I have no option but to do long method.

    Anyway, the SetPropertiesFrom is helpful to me.

    Thanks again.

    Marlon

This discussion has been closed.