Пример #1
0
        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;

            var 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);
        }
Пример #2
0
        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;

            var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int m   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                if (Algorithms.PolyClean_SetTopoDirection(poly, dir))
                {
                    m++;
                }
            });
            Interaction.WriteLine("{0} handled.", m);
        }
Пример #3
0
        public static void PolyClean2()
        {
            double epsilon = Interaction.GetValue("\nEpsilon", _polyClean2Epsilon);

            if (double.IsNaN(epsilon))
            {
                return;
            }
            _polyClean2Epsilon = epsilon;

            var 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);
        }
Пример #4
0
        public void TestHatch4()
        {
            var ids  = Interaction.GetSelection("\nSelect entities");
            var ents = ids.QSelect(entity => entity).ToArray();

            Draw.Hatch("SOLID", ents);
        }
Пример #5
0
        public static void ClosePolyline()
        {
            var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");

            if (ids.Length == 0)
            {
                return;
            }
            if (Interaction.TaskDialog(
                    mainInstruction: ids.Count().ToString() + " polyline(s) selected. Make sure what you select is correct.",
                    yesChoice: "Yes, I promise.",
                    noChoice: "No, I want to double check.",
                    title: "AutoCAD",
                    content: "All polylines in selection will be closed.",
                    footer: "Abuse can mess up the drawing.",
                    expanded: "Commonly used before export."))
            {
                //polys.QForEach(poly => LogManager.Write((poly as Polyline).Closed));
                ids.QForEach <Polyline>(poly =>
                {
                    if (poly.StartPoint.DistanceTo(poly.EndPoint) > 0)
                    {
                        poly.AddVertexAt(poly.NumberOfVertices, poly.StartPoint.ToPoint2d(), 0, 0, 0);
                    }
                });
            }
        }
Пример #6
0
        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(rect => rect.Erase());
        }
Пример #7
0
        public void TestUngroup()
        {
            var ids = Interaction.GetSelection("\nSelect entities");

            Modify.Ungroup(ids);
            var groupDict = HostApplicationServices.WorkingDatabase.GroupDictionaryId.QOpenForRead <DBDictionary>();

            Interaction.WriteLine("{0} groups.", groupDict.Count);
        }
Пример #8
0
        public static void PolyClean5()
        {
            Interaction.WriteLine("Not implemented yet");
            var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");

            ids.QForEach <Polyline>(poly =>
            {
                Algorithms.PolyClean_RemoveColinearPoints(poly);
            });
        }
Пример #9
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(entity => !entity.Layer.Contains("_Label"))
                .QSelect(entity => entity.Layer)
                .Distinct()
                .Select(layer => $"{layer}_Label")
                .ForEach(labelLayer => DbHelper.GetLayerId(labelLayer));
            }
            else
            {
                var    layers    = DbHelper.GetAllLayerNames().Where(layer => !layer.Contains("_Label")).ToArray();
                string layerName = Gui.GetChoice("Select a layer", layers);
                ids = QuickSelection
                      .SelectAll(FilterList.Create().Layer(layerName))
                      .ToArray();

                DbHelper.GetLayerId($"{layerName}_Label");
            }

            List <string> layerNames = new List <string>();

            var texts = new List <MText>();

            ids.QForEach <Entity>(entity =>
            {
                string layerName = entity.Layer;
                layerNames.Add(layerName);
                if (!layerName.Contains("_Label"))
                {
                    var center = entity.GetCenter();
                    var text   = NoDraw.MText(layerName, height, center, 0, true);
                    text.Layer = $"{layerName}_Label";
                    texts.Add(text);
                }
            });
            //int result2 = Gui.GetOption("Layernames", layerNames.ToArray());
            texts.ToArray().AddToCurrentSpace();
        }
Пример #10
0
        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(dt => dt.Erase());
            dts.AddToCurrentSpace();
        }
Пример #11
0
        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(mt => mt.Erase());
            mts.AddToCurrentSpace();
        }
Пример #12
0
        public static void PolyClean0()
        {
            var 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);
        }
Пример #13
0
        public static void PolySplit()
        {
            var ids      = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            var newPolys = new List <Polyline>();
            var pm       = new ProgressMeter();

            pm.Start("Processing...");
            pm.SetLimit(ids.Length);
            ids.QOpenForWrite <Polyline>(list =>
            {
                foreach (var poly in list)
                {
                    var 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 Add to newPolys regardless of whether an intersection exists, otherwise dangling lines would be gone.
                    {
                        newPolys.Add(poly.Clone() as Polyline);
                    }
                    pm.MeterProgress();
                }
            });
            pm.Stop();
            if (newPolys.Count > 0)
            {
                newPolys.ToArray().AddToCurrentSpace();
                ids.QForEach(entity => entity.Erase());
            }
            Interaction.WriteLine("Broke {0} to {1}.", ids.Length, newPolys.Count);
        }
Пример #14
0
        public static void PolyClean()
        {
            var 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);
        }
Пример #15
0
        public static void PolyTrimExtend() // mod 20130228
        {
            double epsilon = Interaction.GetValue("\nEpsilon", _polyTrimExtendEpsilon);

            if (double.IsNaN(epsilon))
            {
                return;
            }
            _polyTrimExtendEpsilon = epsilon;

            var visibleLayers = DbHelper
                                .GetAllLayerIds()
                                .QOpenForRead <LayerTableRecord>()
                                .Where(layer => !layer.IsHidden && !layer.IsFrozen && !layer.IsOff)
                                .Select(layer => layer.Name)
                                .ToList();

            var ids = Interaction
                      .GetSelection("\nSelect polyline", "LWPOLYLINE")
                      .QWhere(pline => visibleLayers.Contains(pline.Layer) && pline.Visible)
                      .ToArray(); // newly 20130729

            var 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)
                    {
                        var end = poly.GetPoint3dAt(index);
                        foreach (var poly1 in list)
                        {
                            if (poly1 != poly)
                            {
                                var 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();
        }
Пример #16
0
 /// <summary>
 /// Gets multiple entities.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="allowedType">The allowed types. e.g. "*LINE,ARC,CIRCLE"</param>
 /// <returns>The entity IDs.</returns>
 public static ObjectId[] GetSelection(string message, string allowedType)
 {
     return(Interaction.GetSelection(message, new TypedValue((int)DxfCode.Start, allowedType)));
 }
Пример #17
0
        public void TestHatch2()
        {
            var ids = Interaction.GetSelection("\nSelect entities");

            Draw.Hatch(ids);
        }
Пример #18
0
 /// <summary>
 /// Gets multiple entities.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="filterList">The filter list.</param>
 /// <returns>The entity IDs.</returns>
 public static ObjectId[] GetSelection(string message, FilterList filterList)
 {
     return(Interaction.GetSelection(message, filterList.ToArray()));
 }