/// <summary> /// Extract the points of a Polyline2d /// </summary> /// <param name="aPolyline"></param> /// <returns>Point2dCollection</returns> public static Point2dCollection GetPointsFromPolyline(Polyline2d aPolyline) { var polyPts = new Point2dCollection(); var polySegments = new DBObjectCollection(); aPolyline.Explode(polySegments); // Cycle through the segments for (var i = 0; i <= polySegments.Count - 1; i++) { // if segment is Line var line = polySegments[i] as Line; if (line != null) { var tempLine = line; polyPts.Add(new Point2d(tempLine.StartPoint.X, tempLine.StartPoint.Y)); polyPts.Add(new Point2d(tempLine.EndPoint.X, tempLine.EndPoint.Y)); } // else if segment is Arc else { var arc = polySegments[i] as Arc; if (arc != null) { var tempArc = arc; polyPts.Add(new Point2d(tempArc.StartPoint.X, tempArc.StartPoint.Y)); polyPts.Add(new Point2d(tempArc.EndPoint.X, tempArc.EndPoint.Y)); } // else is something else - this must never happen else { throw new Exception( "KojtoCAD Error - Can not find the type of this polyline segment. Not Arc nor Line."); } } } RemoveDuplicate(polyPts); return(polyPts); }
public Polycurve PolycurveToSpeckle(Polyline2d polyline) // AC polyline2d can have linear, circlular, or elliptical segments { var polycurve = new Polycurve(units: ModelUnits) { closed = polyline.Closed }; // extract segment curves var segments = new List <ICurve>(); var exploded = new DBObjectCollection(); polyline.Explode(exploded); for (int i = 0; i < exploded.Count; i++) { segments.Add((ICurve)ConvertToSpeckle(exploded[i])); } polycurve.segments = segments; polycurve.length = polyline.Length; polycurve.bbox = BoxToSpeckle(polyline.GeometricExtents, true); return(polycurve); }
CoordinateList ReadCoordination(Polyline2d polyline2D, Transaction tr) { var coordinateList = new CoordinateList(); if (polyline2D.PolyType == Poly2dType.SimplePoly) { foreach (var v in polyline2D) { Vertex2d vertex = null; if (v is ObjectId) { var id = (ObjectId)v; if (id.IsValid) { vertex = tr.GetObject(id, OpenMode.ForRead) as Vertex2d; } } else if (v is Vertex2d) { vertex = (Vertex2d)v; } if (vertex != null) { coordinateList.Add(this.ReadCoordinate(vertex.Position), this.AllowRepeatedCoordinates); } } } else { var dBObjectCollection = new DBObjectCollection(); polyline2D.Explode(dBObjectCollection); try { foreach (var dBObject in dBObjectCollection) { if (dBObject is Arc) { var arc = (Arc)dBObject; coordinateList.Add(this.GetTessellatedCurveCoordinates(arc), false); } else if (dBObject is Line) { var line = (Line)dBObject; coordinateList.Add(this.ReadCoordinate(line.StartPoint), false); coordinateList.Add(this.ReadCoordinate(line.EndPoint), false); } } } finally { foreach (var dBObject in dBObjectCollection) { if (dBObject is IDisposable) { (dBObject as IDisposable).Dispose(); } } } dBObjectCollection.Dispose(); } if (polyline2D.Closed) { coordinateList.Add(coordinateList[0]); } return(coordinateList); }