Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public static void DetectSelfIntersection() // mod 20130202
        {
            var ids   = QuickSelection.SelectAll("LWPOLYLINE").ToArray();
            var meter = new ProgressMeter();

            meter.Start("Detecting...");
            meter.SetLimit(ids.Length);
            var results = ids.QWhere(pline =>
            {
                bool result = (pline as Polyline).IsSelfIntersecting();
                meter.MeterProgress();
                System.Windows.Forms.Application.DoEvents();
                return(result);
            }).ToList();

            meter.Stop();
            if (results.Count() > 0)
            {
                Interaction.WriteLine("{0} detected.", results.Count());
                Interaction.ZoomHighlightView(results);
            }
            else
            {
                Interaction.WriteLine("0 detected.");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// View entities interactively.
        /// </summary>
        /// <param name="entityIds">The entity IDs.</param>
        /// <param name="action">The action.</param>
        public static void ZoomHighlightView(List <ObjectId> entityIds, Action <int> action = null) // newly 20130815
        {
            if (entityIds.Count > 0)
            {
                var highlightIds = new List <ObjectId>();
                while (true)
                {
                    string input = Interaction.GetString("\nType in a number to view, press ENTER to exit: ");
                    if (input == null)
                    {
                        break;
                    }
                    var index = Convert.ToInt32(input);
                    if (index <= 0 || index > entityIds.Count)
                    {
                        Interaction.WriteLine("Invalid entity number.");
                        continue;
                    }

                    action?.Invoke(index);
                    highlightIds.Clear();
                    highlightIds.Add(entityIds[index - 1]);
                    Interaction.ZoomObjects(highlightIds);
                    Interaction.HighlightObjects(highlightIds);
                }
            }
        }
Exemplo n.º 6
0
        public void TestKeywords()
        {
            string[] keys = { "A", "B", "C", "D" };
            var      key  = Interaction.GetKeywords("\nChoose an option", keys, 3);

            Interaction.WriteLine("You chose {0}.", key);
        }
Exemplo n.º 7
0
        public static void SaveSelection()
        {
            var ids = Interaction.GetPickSet();

            if (ids.Length == 0)
            {
                Interaction.WriteLine("No entity selected.");
                return;
            }
            string name = Interaction.GetString("\nSelection name");

            if (name == null)
            {
                return;
            }
            if (CustomDictionary.GetValue("Selections", name) != string.Empty)
            {
                Interaction.WriteLine("Selection with the same name already exists.");
                return;
            }
            var    handles   = ids.QSelect(entity => entity.Handle.Value.ToString()).ToArray();
            string dictValue = string.Join("|", handles);

            CustomDictionary.SetValue("Selections", name, dictValue);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void TestSelection()
        {
            var    point = Interaction.GetPoint("\nPoint");
            double value = Interaction.GetDistance("\nSize");
            var    size  = new Vector3d(value, value, 0);
            var    ids   = Interaction.GetWindowSelection(point - size, point + size);

            Interaction.WriteLine("{0} entities selected.", ids.Count());
        }
Exemplo n.º 10
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);
            });
        }
Exemplo n.º 11
0
 public void TestTaskDialog()
 {
     if (Interaction.TaskDialog("I prefer", "Work", "Life", "WLB poll", "You have to choose one...", "...and only choose one.", "No other choices."))
     {
         Interaction.WriteLine("You are promoted.");
     }
     else
     {
         Interaction.WriteLine("You are fired.");
     }
 }
Exemplo n.º 12
0
 public void TestCustomDictionary()
 {
     CustomDictionary.SetValue("dict1", "A", "apple");
     CustomDictionary.SetValue("dict1", "B", "orange");
     CustomDictionary.SetValue("dict1", "A", "banana");
     CustomDictionary.SetValue("dict2", "A", "peach");
     foreach (var dict in CustomDictionary.GetDictionaryNames())
     {
         Interaction.WriteLine(dict);
     }
     Interaction.WriteLine(CustomDictionary.GetValue("dict1", "A"));
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public static void PolyLanding()
        {
            var ids            = QuickSelection.SelectAll("*LINE,ARC").ToArray();
            var landingLineIds = new List <ObjectId>();

            while (true)
            {
                var p = Interaction.GetPoint("\nSpecify a point");
                if (p.IsNull())
                {
                    break;
                }
                var    landings = ids.QSelect(entity => (entity as Curve).GetClosestPointTo(p, false)).ToArray();
                double minDist  = landings.Min(point => point.DistanceTo(p));
                var    landing  = landings.First(point => point.DistanceTo(p) == minDist);
                Interaction.WriteLine("Shortest landing distance of point ({0:0.00},{1:0.00}) is {2:0.00}.", p.X, p.Y, minDist);
                landingLineIds.Add(Draw.Line(p, landing));
            }
            landingLineIds.QForEach(entity => entity.Erase());
        }
Exemplo n.º 17
0
        public static void PolylineInfo() // mod by WY 20130202
        {
            var id = Interaction.GetEntity("\nSpecify a polyline", typeof(Polyline));

            if (id == ObjectId.Null)
            {
                return;
            }
            var poly = id.QOpenForRead <Polyline>();

            for (int i = 0; i <= poly.EndParam; i++)
            {
                Interaction.WriteLine("[Point {0}] coord: {1}; bulge: {2}", i, poly.GetPointAtParameter(i), poly.GetBulgeAt(i));
            }
            var    txtIds = new List <ObjectId>();
            double height = poly.GeometricExtents.MaxPoint.DistanceTo(poly.GeometricExtents.MinPoint) / 50.0;

            for (int i = 0; i < poly.NumberOfVertices; i++)
            {
                txtIds.Add(Draw.MText(i.ToString(), height, poly.GetPointAtParameter(i), 0, true));
            }
            Interaction.GetString("\nPress ENTER to exit");
            txtIds.QForEach(mt => mt.Erase());
        }