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 void TestPolygon() { int n; while (true) { double d = Interaction.GetValue("\nNumber of edges"); if (double.IsNaN(d)) { return; } n = (int)d; if (n > 2) { break; } } Point3d center = Interaction.GetPoint("\nCenter"); Draw.Circle(center, 5); Point3d end = Interaction.GetPoint("\nOne vertex"); Draw.Circle(end, 5); Draw.Polygon(n, center, end); }
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 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 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 TestOffset() { ObjectId id = Interaction.GetEntity("\nPolyline"); Polyline poly = id.QOpenForRead <Polyline>(); double value = Interaction.GetValue("\nOffset"); poly.OffsetPoly(Enumerable.Range(0, poly.NumberOfVertices).Select(x => value).ToArray()).AddToModelSpace(); }
public void TestDivide() { var id = Interaction.GetEntity("\nSelect curve"); var cv = id.QOpenForRead <Curve>(); int num = (int)Interaction.GetValue("\nNumbers"); Draw.Divide(cv, num, new DBPoint()); }
public void TestMeasure() { var id = Interaction.GetEntity("\nSelect curve"); var cv = id.QOpenForRead <Curve>(); double length = Interaction.GetValue("\nInterval"); Draw.Measure(cv, length, new DBPoint()); }
public static void LoadPoints() { try { string txt = Gui.InputBox("输入基站坐标"); Point3d zero = Interaction.GetPoint("ZeroPoint"); double size = Interaction.GetValue("点(基站)大小", 1000); double height = Interaction.GetValue("文字高度", 1000); //string key = Interaction.GetString("搜索", ""); string key = ""; string[] lines = txt.Split('\n'); for (int i = 0; i < lines.Length; i++) { string line = lines[i].Trim(); if (string.IsNullOrEmpty(line)) { continue; } string[] parts = line.Split(','); string name = ""; double x = 0, y = 0, z = 0; if (parts.Length == 5) { name = parts[0]; x = parts[2].ToDouble(); y = parts[3].ToDouble(); z = parts[4].ToDouble(); } if (parts.Length == 4) { name = parts[0]; x = parts[1].ToDouble(); y = parts[2].ToDouble(); z = parts[3].ToDouble(); } if (string.IsNullOrEmpty(key) || name == key) { Point3d point = new Point3d(x + zero.X, y + zero.Y, z + zero.Z); Draw.Point(point); if (size > 0) { Draw.Circle(point, size); } if (height > 0) { Draw.Text(name, height, point); } } } } catch (System.Exception ex) { MyTool.TextReport("Exception", ex.ToString(), 700, 500); } }
public static void GetParkInfoEx() { string parkName = Interaction.GetString("输入厂区名称(默认:厂区A)"); if (string.IsNullOrEmpty(parkName)) { parkName = "厂区A"; } int count = (int)Interaction.GetValue("输入最大大楼楼层(默认:10)", 10); GetCADOtherCommands.GetParkInfoEx(parkName, count); }
public static void GetAllFloors() { string buildingName = Interaction.GetString("输入大楼名称(默认:大楼X)"); if (string.IsNullOrEmpty(buildingName)) { buildingName = "大楼X"; } int count = (int)Interaction.GetValue("输入大楼楼层(默认:5)", 5); GetCADOtherCommands.GetAllFloors(buildingName, count, ""); }
public void TestEllipse() { Point3d center = Interaction.GetPoint("\nCenter"); Draw.Circle(center, 5); Point3d endX = Interaction.GetPoint("\nEnd of one axis"); Draw.Circle(endX, 5); double radiusY = Interaction.GetValue("\nRadius of another axis"); Draw.Ellipse(center, endX, radiusY); }
public void TestArc2() { Point3d start = Interaction.GetPoint("\nStart"); Draw.Circle(start, 5); Point3d center = Interaction.GetPoint("\nCenter"); Draw.Circle(center, 5); double angle = Interaction.GetValue("\nAngle"); Draw.ArcSCA(start, center, angle); }
public static void ShowObject() { ObjectId[] ids = QuickSelection.SelectAll().ToArray(); double handle1 = Interaction.GetValue("Handle of entity"); if (double.IsNaN(handle1)) { return; } long handle2 = Convert.ToInt64(handle1); var id = HostApplicationServices.WorkingDatabase.GetObjectId(false, new Handle(handle2), 0); var col = new ObjectId[] { id }; Interaction.HighlightObjects(col); Interaction.ZoomObjects(col); }
public static void LoadPoints() { string txt = Gui.InputBox("输入坐标"); double size = Interaction.GetValue("点大小", 2); double height = Interaction.GetValue("文字高度", 2); string key = Interaction.GetString("搜索", ""); string[] lines = txt.Split('\n'); for (int i = 0; i < lines.Length; i++) { string line = lines[i].Trim(); if (string.IsNullOrEmpty(line)) { continue; } string[] parts = line.Split(','); string name = parts[0]; double x = parts[2].ToDouble(); double y = parts[3].ToDouble(); double z = parts[4].ToDouble(); if (string.IsNullOrEmpty(key) || name == key) { Point3d point = new Point3d(x, y, z); Draw.Point(point); if (size > 0) { Draw.Circle(point, size); } if (height > 0) { Draw.Text(name, height, point); } } } }