public static Entity[] BreakOnPoint(this Curve ent, Point2d at, QuickTransaction tr, bool commitAtEnd = false) { if (ent == null) { throw new ArgumentNullException(nameof(ent)); } if (tr == null) { throw new ArgumentNullException(nameof(tr)); } try { var btr = (BlockTableRecord)tr.GetObject(tr.Db.CurrentSpaceId, OpenMode.ForWrite); Point3d att = at.ToPoint3D(); att.TransformBy(tr.Editor.CurrentUserCoordinateSystem.Inverse()); // Check that the point is on the curve att = ent.GetClosestPointTo(att, false); var breakPoints = new Point3dCollection(); var newCurves = new DBObjectCollection(); // Get the segments according to the trim points breakPoints.Add(att); newCurves = ent.GetSplitCurves(breakPoints); if (newCurves == null) { tr.Editor.WriteMessage("\nGetSplitCurves failed : Error"); return(new Entity[0]); } var ret = new List <Entity>(); // Here we add the segments to the database with different colors for (var i = 0; i < newCurves.Count; i++) { var pent = (Entity)newCurves[i]; pent.SetPropertiesFrom(ent); btr.AppendEntity(pent); tr.AddNewlyCreatedDBObject(pent, true); ret.Add(pent); } ent.UpgradeOpen(); ent.Erase(); if (commitAtEnd) { tr.Commit(); } return(ret.ToArray()); } catch (Exception ex) { Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace); return(new Entity[0]); } finally { } }
/// <summary> /// Shifts on line from a specific point for <paramref name="distance"/> length.<br></br>Returns true if successful, false if exceeded the limits - will return basepoint! /// </summary> /// <param name="ent">Ent</param> /// <param name="basepoint">the point to offset from</param> /// <param name="distance">The distance to offset</param> /// <returns>true if successful, false if exceeded the limits - will return basepoint!</returns> public static Tuple <Point2d, bool> OffsetToEnd(this Curve ent, Point2d basepoint, double distance) { var basepoint3 = ent.GetClosestPointTo(basepoint.ToPoint3D(), true); basepoint = basepoint3.ToPoint2D(); try { var dis = ent.GetDistAtPoint(basepoint3); var extra = dis + distance; var pt = ent.GetPointAtDist(extra); return(Tuple.Create(pt.ToPoint2D(), true)); } catch (Exception e) { Quick.WriteLine("\nInvalid Input, offset exceeds curve's limits.\n" + e); return(Tuple.Create(basepoint, false)); } }
public static int ClosestVertexIndex(this Polyline pl, Point2d pt) { pt = pl.GetClosestPointTo(pt.ToPoint3D(), true).ToPoint2D(); for (var i = 0; i < pl.NumberOfVertices; i++) { var dbl = new double(); var ons = pl.OnSegmentAt(i, pt, dbl); if (ons) { return(i); } } return(-1); }