public void createPolyline(Point3dCollection pts) { LineSegment3d segmentLine = null; CircularArc3d segmentArc = null; int segmentCounter; Point3d linePt0 = new Point3d(); Point3d linePt1 = new Point3d(); double anglePt0 = -1; double anglePt1 = -1; bool pt0IsaLine = false; bool pt0IsanArc = false; CoordinateSystem3d cs = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d; Plane plan = new Plane(Point3d.Origin, cs.Zaxis); double param = new double(); //loop through point and get segment type. Create new lines foreach (Point3d pt in pts) { //oint3d closest = _runningLine.GetClosestPointTo(pt, false); for (segmentCounter = 0; segmentCounter < _runningLine.NumberOfVertices; segmentCounter++) { //try //{ if (_runningLine.OnSegmentAt(segmentCounter, pt.Convert2d(plan), param)) { if (_runningLine.GetSegmentType(segmentCounter) == SegmentType.Arc) { segmentArc = _runningLine.GetArcSegmentAt(segmentCounter); if (pts.IndexOf(pt) == 0) { anglePt0 = segmentArc.Center.GetVectorTo(pt).AngleOnPlane(plan); pt0IsanArc = true; break; } if (pt0IsaLine) { if ((segmentLine.GetDistanceTo(pt) / segmentLine.Length) < .5) { linePt1 = new Point3d(segmentLine.EndPoint.X, segmentLine.EndPoint.Y, segmentLine.EndPoint.Z); } else { linePt1 = new Point3d(segmentLine.StartPoint.X, segmentLine.StartPoint.Y, segmentLine.StartPoint.Z); } anglePt0 = segmentArc.Center.GetVectorTo(linePt1).AngleOnPlane(plan); } anglePt1 = segmentArc.Center.GetVectorTo(pt).AngleOnPlane(plan); break; } else //if not an arc is a line { segmentLine = _runningLine.GetLineSegmentAt(segmentCounter); if (pts.IndexOf(pt) == 0) { linePt0 = new Point3d(pt.X, pt.Y, pt.Z); pt0IsaLine = true; break; } linePt1 = new Point3d(pt.X, pt.Y, pt.Z); if (pt0IsanArc) { if (pt.GetVectorTo(segmentLine.StartPoint).Length > pt.GetVectorTo(segmentLine.EndPoint).Length) { linePt0 = new Point3d(segmentLine.EndPoint.X, segmentLine.EndPoint.Y, segmentLine.EndPoint.Z); } else { linePt0 = new Point3d(segmentLine.StartPoint.X, segmentLine.StartPoint.Y, segmentLine.StartPoint.Z); } anglePt1 = segmentArc.Center.GetVectorTo(linePt0).AngleOnPlane(plan); } linePt1 = new Point3d(pt.X, pt.Y, pt.Z); break; } } } } Transaction tr = acCurDb.TransactionManager.StartTransaction(); using (tr) { Arc dbArc = null; Line dbLine = null; // Open the Block table record for read BlockTable acBlkTbl; acBlkTbl = tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec; acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (anglePt0 >= 0) { if (anglePt0 > anglePt1) { dbArc = new Arc(segmentArc.Center, segmentArc.Radius, anglePt1, anglePt0); } else { dbArc = new Arc(segmentArc.Center, segmentArc.Radius, anglePt0, anglePt1); } } if (linePt0 != null) { dbLine = new Line(linePt0, linePt1); } if (dbArc != null && dbLine != null) { Polyline pl1 = new Polyline(); pl1.AddVertexAt(0, segmentLine.StartPoint.Convert2d(plan), 0, 0, 0); pl1.AddVertexAt(1, segmentLine.EndPoint.Convert2d(plan), 0, 0, 0); //pl1.AddVertexAt(2, segmentArc.EndPoint.Convert2d(plan), segmentArc.); } if (dbArc != null) { acBlkTblRec.AppendEntity(dbArc); tr.AddNewlyCreatedDBObject(dbArc, true); } if (dbLine != null) { acBlkTblRec.AppendEntity(dbLine); tr.AddNewlyCreatedDBObject(dbLine, true); } tr.Commit(); } }