Community
Hi All,
I have one question, hope everybody can help me. How can i set startpoint for polyline. And New StartPoint have to near Original System(O). I have attached image.
You can easily redraw this polyline, if this one
is have the straight segments only, here is a quick code for this case:
' for using to updating a straight polyline segments only <CommandMethod("repst", CommandFlags.Redraw)> _ 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 & "Select a polyline : ") peo1.SetRejectMessage(vbLf & "You have to select polyline only!") peo1.AddAllowedClass(GetType(Polyline), False) Dim res1 As PromptEntityResult = ed.GetEntity(peo1) If res1.Status <> 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 & "Pick a new start vertex point: ") Dim es As PromptPointResult = ed.GetPoint(prOpt) If es.Status <> PromptStatus.OK Then If es.Status = PromptStatus.Cancel Then ed.WriteMessage(vbLf & "Interrupted by user") Return Else ed.WriteMessage(vbLf & "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 & "{0}", ex.StackTrace) Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf & "{0}" & vbLf & "{1}" & vbLf, ex.Message, ex.StackTrace) Finally Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", osm) End Try End Sub
Thanks. If my polyline have arc(CircularArc2d), line... I will do the same above code.