<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: set startpoint for polyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4715129#M46256</link>
    <description>&lt;P&gt;You can easily redraw this polyline, if this one&lt;/P&gt;
&lt;P&gt;is have the straight segments only, here is a quick code&amp;nbsp;for this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        ' for using to updating a straight polyline segments only
        &amp;lt;CommandMethod("repst", CommandFlags.Redraw)&amp;gt; _
        Public Shared Sub TestChangePolyStart()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim ucs As CoordinateSystem3d = ed.CurrentUserCoordinateSystem.CoordinateSystem3d

            Dim osm As Object = Nothing

            Dim mat As Matrix3d = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, ucs.Origin, ucs.Xaxis, _
             ucs.Yaxis, ucs.Zaxis)

            Try
                Using doclock As DocumentLock = doc.LockDocument()
                    osm = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("osmode")

                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 1)

                    Dim peo1 As New PromptEntityOptions(vbLf &amp;amp; "Select a  polyline : ")

                    peo1.SetRejectMessage(vbLf &amp;amp; "You have to select polyline only!")

                    peo1.AddAllowedClass(GetType(Polyline), False)

                    Dim res1 As PromptEntityResult = ed.GetEntity(peo1)

                    If res1.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                        Return
                    End If

                    Dim id As ObjectId = res1.ObjectId
                    Dim p1 As Point3d = res1.PickedPoint.TransformBy(mat)

                    Dim prOpt As New PromptPointOptions(vbLf &amp;amp; "Pick a new start vertex point: ")

                    Dim es As PromptPointResult = ed.GetPoint(prOpt)

                    If es.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                        If es.Status = PromptStatus.Cancel Then
                            ed.WriteMessage(vbLf &amp;amp; "Interrupted by user")
                            Return
                        Else
                            ed.WriteMessage(vbLf &amp;amp; "Error on specifying a point")
                            Return
                        End If
                    End If

                    Dim new3dPt As Point3d = es.Value.TransformBy(mat)


                    Using tr As Transaction = db.TransactionManager.StartTransaction()
                        Dim poly As Polyline = DirectCast(tr.GetObject(id, OpenMode.ForRead), Polyline)

                        Dim wid As Double = poly.ConstantWidth

                        Dim new2dPt As New Point2d(new3dPt.X, new3dPt.Y)

                        Dim c As Integer = 0

                        Dim points As New List(Of Point2d)()
                        Dim sb As New StringBuilder()
                        For c = 0 To poly.NumberOfVertices - 1

                            points.Add(poly.GetPoint2dAt(c))
                        Next


                        Dim pos As Integer = points.IndexOf(new2dPt)

                        'Reverse List from given position using LINQ implementation

                        Dim tail As IEnumerable(Of Point2d) = points.Take(pos)

                        Dim head As IEnumerable(Of Point2d) = points.Except(tail)

                        Dim newpoints As IEnumerable(Of Point2d) = head.Concat(tail)

                        Dim pts As List(Of Point2d) = newpoints.ToList()
                        '________________________________________

                        Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

                        poly.UpgradeOpen()

                        Dim newpoly As New Polyline(poly.NumberOfVertices)

                        newpoly.Closed = poly.Closed

                        For c = 0 To pts.Count - 1
                            newpoly.AddVertexAt(c, CType(pts(c), Point2d), 0, wid, wid)
                        Next
                        newpoly.Closed = poly.Closed

                        btr.AppendEntity(newpoly)

                        tr.AddNewlyCreatedDBObject(newpoly, True)

                        newpoly.SetPropertiesFrom(poly)

                        poly.Erase()

                        tr.Commit()

                        ed.Regen()

                    End Using
                End Using
            Catch ex As System.Exception
                ed.WriteMessage(vbLf &amp;amp; "{0}", ex.StackTrace)
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf &amp;amp; "{0}" &amp;amp; vbLf &amp;amp; "{1}" &amp;amp; vbLf, ex.Message, ex.StackTrace)
            Finally
                Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", osm)
            End Try
        End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Dec 2013 16:00:26 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2013-12-25T16:00:26Z</dc:date>
    <item>
      <title>set startpoint for polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4714339#M46254</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have one question, hope everybody can help me. How can i set startpoint for polyline. And &lt;FONT color="#FF0000"&gt;New StartPoint&lt;/FONT&gt; have to near &lt;FONT color="#FF0000"&gt;Original System(O)&lt;/FONT&gt;. I have attached image.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Dec 2013 06:59:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4714339#M46254</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-12-25T06:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: set startpoint for polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4715129#M46256</link>
      <description>&lt;P&gt;You can easily redraw this polyline, if this one&lt;/P&gt;
&lt;P&gt;is have the straight segments only, here is a quick code&amp;nbsp;for this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        ' for using to updating a straight polyline segments only
        &amp;lt;CommandMethod("repst", CommandFlags.Redraw)&amp;gt; _
        Public Shared Sub TestChangePolyStart()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim ucs As CoordinateSystem3d = ed.CurrentUserCoordinateSystem.CoordinateSystem3d

            Dim osm As Object = Nothing

            Dim mat As Matrix3d = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, ucs.Origin, ucs.Xaxis, _
             ucs.Yaxis, ucs.Zaxis)

            Try
                Using doclock As DocumentLock = doc.LockDocument()
                    osm = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("osmode")

                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 1)

                    Dim peo1 As New PromptEntityOptions(vbLf &amp;amp; "Select a  polyline : ")

                    peo1.SetRejectMessage(vbLf &amp;amp; "You have to select polyline only!")

                    peo1.AddAllowedClass(GetType(Polyline), False)

                    Dim res1 As PromptEntityResult = ed.GetEntity(peo1)

                    If res1.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                        Return
                    End If

                    Dim id As ObjectId = res1.ObjectId
                    Dim p1 As Point3d = res1.PickedPoint.TransformBy(mat)

                    Dim prOpt As New PromptPointOptions(vbLf &amp;amp; "Pick a new start vertex point: ")

                    Dim es As PromptPointResult = ed.GetPoint(prOpt)

                    If es.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                        If es.Status = PromptStatus.Cancel Then
                            ed.WriteMessage(vbLf &amp;amp; "Interrupted by user")
                            Return
                        Else
                            ed.WriteMessage(vbLf &amp;amp; "Error on specifying a point")
                            Return
                        End If
                    End If

                    Dim new3dPt As Point3d = es.Value.TransformBy(mat)


                    Using tr As Transaction = db.TransactionManager.StartTransaction()
                        Dim poly As Polyline = DirectCast(tr.GetObject(id, OpenMode.ForRead), Polyline)

                        Dim wid As Double = poly.ConstantWidth

                        Dim new2dPt As New Point2d(new3dPt.X, new3dPt.Y)

                        Dim c As Integer = 0

                        Dim points As New List(Of Point2d)()
                        Dim sb As New StringBuilder()
                        For c = 0 To poly.NumberOfVertices - 1

                            points.Add(poly.GetPoint2dAt(c))
                        Next


                        Dim pos As Integer = points.IndexOf(new2dPt)

                        'Reverse List from given position using LINQ implementation

                        Dim tail As IEnumerable(Of Point2d) = points.Take(pos)

                        Dim head As IEnumerable(Of Point2d) = points.Except(tail)

                        Dim newpoints As IEnumerable(Of Point2d) = head.Concat(tail)

                        Dim pts As List(Of Point2d) = newpoints.ToList()
                        '________________________________________

                        Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

                        poly.UpgradeOpen()

                        Dim newpoly As New Polyline(poly.NumberOfVertices)

                        newpoly.Closed = poly.Closed

                        For c = 0 To pts.Count - 1
                            newpoly.AddVertexAt(c, CType(pts(c), Point2d), 0, wid, wid)
                        Next
                        newpoly.Closed = poly.Closed

                        btr.AppendEntity(newpoly)

                        tr.AddNewlyCreatedDBObject(newpoly, True)

                        newpoly.SetPropertiesFrom(poly)

                        poly.Erase()

                        tr.Commit()

                        ed.Regen()

                    End Using
                End Using
            Catch ex As System.Exception
                ed.WriteMessage(vbLf &amp;amp; "{0}", ex.StackTrace)
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf &amp;amp; "{0}" &amp;amp; vbLf &amp;amp; "{1}" &amp;amp; vbLf, ex.Message, ex.StackTrace)
            Finally
                Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", osm)
            End Try
        End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Dec 2013 16:00:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4715129#M46256</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2013-12-25T16:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: set startpoint for polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4715265#M46257</link>
      <description>&lt;P&gt;Thanks. If my polyline have arc(CircularArc2d), line... I will do the same above code.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2013 02:17:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/set-startpoint-for-polyline/m-p/4715265#M46257</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-12-26T02:17:03Z</dc:date>
    </item>
  </channel>
</rss>

