Example #1
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();
        }
Example #2
0
        public static void LoadSelection()
        {
            string name = Gui.GetChoice("Which selection to load?", CustomDictionary.GetEntryNames("Selections").ToArray());

            if (name == string.Empty)
            {
                return;
            }
            string dictValue = CustomDictionary.GetValue("Selections", name);
            var    handles   = dictValue.Split('|').Select(value => new Handle(Convert.ToInt64(value))).ToList();
            var    ids       = new List <ObjectId>();

            handles.ForEach(value =>
            {
                var id = ObjectId.Null;
                if (HostApplicationServices.WorkingDatabase.TryGetObjectId(value, out id))
                {
                    ids.Add(id);
                }
            });
            Interaction.SetPickSet(ids.ToArray());
        }