public static void PolyClean3() { double value = Interaction.GetValue("\nNumber of segs to fit an arc, 0 for smart determination", 0); if (double.IsNaN(value)) { return; } int n = (int)value; ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); var entsToAdd = new List <Polyline>(); ids.QForEach <Polyline>(poly => { var pts = poly.GetPolylineFitPoints(n); var poly1 = NoDraw.Pline(pts); poly1.Layer = poly.Layer; try { poly1.ConstantWidth = poly.ConstantWidth; } catch { } poly1.XData = poly.XData; poly.Erase(); entsToAdd.Add(poly1); }); entsToAdd.ToArray().AddToCurrentSpace(); Interaction.WriteLine("{0} handled.", entsToAdd.Count); }
public static void PolyClean2() { double epsilon = Interaction.GetValue("\nEpsilon", _polyClean2Epsilon); if (double.IsNaN(epsilon)) { return; } _polyClean2Epsilon = epsilon; ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); int m = 0; int n = 0; ids.QForEach <Polyline>(poly => { int count = Algorithms.PolyClean_ReducePoints(poly, epsilon); if (count > 0) { m++; n += count; } }); Interaction.WriteLine("{1} vertex removed from {0} polyline.", m, n); }
public static void PolyClean4() { double value = Interaction.GetValue("\nDirection:1-R to L;2-B to T;3-L to R;4-T to B"); if (double.IsNaN(value)) { return; } int n = (int)value; if (!new int[] { 1, 2, 3, 4 }.Contains(n)) { return; } Algorithms.Direction dir = (Algorithms.Direction)n; ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); int m = 0; ids.QForEach <Polyline>(poly => { m += Algorithms.PolyClean_SetTopoDirection(poly, dir); }); Interaction.WriteLine("{0} handled.", m); }
public void TestHatch4() { ObjectId[] ids = Interaction.GetSelection("\nSelect entities"); var ents = ids.QSelect(x => x).ToArray(); Draw.Hatch("SOLID", ents); }
public static void PolyClean3() { double value = Interaction.GetValue("\n距离,默认为2", 2); if (double.IsNaN(value)) { return; } double n = value; ObjectId[] ids = Interaction.GetSelection("\n选择多段线", "LWPOLYLINE"); var entsToAdd = new List <Polyline>(); ids.QForEach <Polyline>(poly => { var pts = poly.GetPolylineDivPoints(n); var poly1 = NoDraw.Pline(pts); poly1.Layer = poly.Layer; try { poly1.ConstantWidth = poly.ConstantWidth; } catch { } poly1.XData = poly.XData; poly.Erase(); entsToAdd.Add(poly1); }); entsToAdd.ToArray().AddToCurrentSpace(); Interaction.WriteLine("{0} handled.", entsToAdd.Count); }
public static void PolyTrimExtend() // mod 20130228 { double epsilon = Interaction.GetValue("\nEpsilon", _polyTrimExtendEpsilon); if (double.IsNaN(epsilon)) { return; } _polyTrimExtendEpsilon = epsilon; ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); var visibleLayers = DbHelper.GetAllLayerIds().QOpenForRead <LayerTableRecord>().Where(x => !x.IsHidden && !x.IsFrozen && !x.IsOff).Select(x => x.Name).ToList(); ids = ids.QWhere(x => visibleLayers.Contains(x.Layer) && x.Visible == true).ToArray(); // newly 20130729 ProgressMeter pm = new ProgressMeter(); pm.Start("Processing..."); pm.SetLimit(ids.Length); ids.QOpenForWrite <Polyline>(list => { foreach (var poly in list) { int[] indices = { 0, poly.NumberOfVertices - 1 }; foreach (int index in indices) { Point3d end = poly.GetPoint3dAt(index); foreach (var poly1 in list) { if (poly1 != poly) { Point3d closest = poly1.GetClosestPointTo(end, false); double dist = closest.DistanceTo(end); double dist1 = poly1.StartPoint.DistanceTo(end); double dist2 = poly1.EndPoint.DistanceTo(end); double distance = poly1.GetDistToPoint(end); if (poly1.GetDistToPoint(end) > 0) { if (dist1 <= dist2 && dist1 <= dist && dist1 < epsilon) { poly.SetPointAt(index, new Point2d(poly1.StartPoint.X, poly1.StartPoint.Y)); } else if (dist2 <= dist1 && dist2 <= dist && dist2 < epsilon) { poly.SetPointAt(index, new Point2d(poly1.EndPoint.X, poly1.EndPoint.Y)); } else if (dist <= dist1 && dist <= dist2 && dist < epsilon) { poly.SetPointAt(index, new Point2d(closest.X, closest.Y)); } } } } } pm.MeterProgress(); } }); pm.Stop(); }
public void TestUngroup() { ObjectId[] ids = Interaction.GetSelection("\nSelect entities"); Modify.Ungroup(ids); DBDictionary groupDict = HostApplicationServices.WorkingDatabase.GroupDictionaryId.QOpenForRead <DBDictionary>(); Interaction.WriteLine("{0} groups.", groupDict.Count); }
public static void ShowExtents() // newly 20130815 { var ids = Interaction.GetSelection("\nSelect entity"); var extents = ids.GetExtents(); var rectId = Draw.Rectang(extents.MinPoint, extents.MaxPoint); Interaction.GetString("\nPress ENTER to exit"); rectId.QOpenForWrite(x => x.Erase()); }
public static void PolyClean5() { Interaction.WriteLine("Not implemented yet"); ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); ids.QForEach <Polyline>(poly => { Algorithms.PolyClean_RemoveColinearPoints(poly); }); }
public static void DT2MT() // newly 20130815 { var ids = Interaction.GetSelection("\nSelect Text", "TEXT"); var dts = ids.QOpenForRead <DBText>().Select(dt => { var mt = NoDraw.MText(dt.TextString, dt.Height, dt.Position, dt.Rotation, false); mt.Layer = dt.Layer; return(mt); }).ToArray(); ids.QForEach(x => x.Erase()); dts.AddToCurrentSpace(); }
public static void MT2DT() // newly 20130815 { var ids = Interaction.GetSelection("\nSelect MText", "MTEXT"); var mts = ids.QOpenForRead <MText>().Select(mt => { var dt = NoDraw.Text(mt.Text, mt.TextHeight, mt.Location, mt.Rotation, false, mt.TextStyleName); dt.Layer = mt.Layer; return(dt); }).ToArray(); ids.QForEach(x => x.Erase()); mts.AddToCurrentSpace(); }
public static void PolyClean0() { ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); int n = 0; ids.QForEach <Polyline>(poly => { if (poly.Length == 0) { poly.Erase(); n++; } }); Interaction.WriteLine("{0} eliminated.", n); }
public static void PolyClean() { ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); int m = 0; int n = 0; ids.QForEach <Polyline>(poly => { int count = Algorithms.PolyClean_RemoveDuplicatedVertex(poly); if (count > 0) { m++; n += count; } }); Interaction.WriteLine("{1} vertex removed from {0} polyline.", m, n); }
public static void PolySplit() { ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); List <Polyline> newPolys = new List <Polyline>(); ProgressMeter pm = new ProgressMeter(); pm.Start("Processing..."); pm.SetLimit(ids.Length); ids.QOpenForWrite <Polyline>(list => { foreach (var poly in list) { Point3dCollection intersectPoints = new Point3dCollection(); foreach (var poly1 in list) { if (poly1 != poly) { poly.IntersectWith3264(poly1, Intersect.OnBothOperands, intersectPoints); } } var ipParams = intersectPoints.Cast <Point3d>().Select(ip => poly.GetParamAtPointX(ip)).OrderBy(param => param).ToArray(); if (intersectPoints.Count > 0) { var curves = poly.GetSplitCurves(new DoubleCollection(ipParams)); foreach (var curve in curves) { newPolys.Add(curve as Polyline); } } else // mod 20130227 不管有无交点,都要添加到newPolys,否则孤立线将消失。 { newPolys.Add(poly.Clone() as Polyline); } pm.MeterProgress(); } }); pm.Stop(); if (newPolys.Count > 0) { newPolys.ToArray().AddToCurrentSpace(); ids.QForEach(x => x.Erase()); } Interaction.WriteLine("Broke {0} to {1}.", ids.Length, newPolys.Count); }
public static void ClosePolyline() { ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE"); if (ids.Length == 0) { return; } if (Interaction.TaskDialog(ids.Count().ToString() + " polyline(s) selected. Make sure what you select is correct.", "Yes, I promise.", "No, I want to check.", "AutoCAD", "All polylines in selection will be closed.", "Abuse can mess up the drawing.", "Commonly used before export.") == true) { //polys.QForEach(x => LogManager.Write((x as Polyline).Closed)); ids.QForEach <Polyline>(poly => { if (poly.StartPoint.DistanceTo(poly.EndPoint) > 0) { poly.AddVertexAt(poly.NumberOfVertices, poly.StartPoint.ToPoint2d(), 0, 0, 0); } }); } }
public static void ShowLayerName() { double height = 10; string[] range = { "By entities", "By layers" }; int result = Gui.GetOption("Choose one way", range); if (result == -1) { return; } ObjectId[] ids; if (result == 0) { ids = Interaction.GetSelection("\nSelect entities"); ids.QWhere(x => !x.Layer.Contains("_Label")).QSelect(x => x.Layer).Distinct().Select(x => string.Format("{0}_Label", x)).ToList().ForEach(x => DbHelper.GetLayerId(x)); } else { var layers = DbHelper.GetAllLayerNames().Where(x => !x.Contains("_Label")).ToArray(); string layer = Gui.GetChoice("Select a layer", layers); ids = QuickSelection.SelectAll().QWhere(x => x.Layer == layer).ToArray(); DbHelper.GetLayerId(string.Format("{0}_Label", layer)); } var texts = new List <MText>(); ids.QForEach <Entity>(ent => { string layerName = ent.Layer; if (!layerName.Contains("_Label")) { Point3d center = ent.GetCenter(); MText text = NoDraw.MText(layerName, height, center, 0, true); text.Layer = string.Format("{0}_Label", layerName); texts.Add(text); } }); texts.ToArray().AddToCurrentSpace(); }
public void TestHatch2() { ObjectId[] ids = Interaction.GetSelection("\nSelect entities"); Draw.Hatch(ids); }