private bool GetOrMakeLayer(string layerName, AcadDb.Transaction tr, out string cleanName)
        {
            cleanName = Utils.RemoveInvalidChars(layerName);
            try
            {
                AcadDb.LayerTable lyrTbl = tr.GetObject(Doc.Database.LayerTableId, AcadDb.OpenMode.ForRead) as AcadDb.LayerTable;
                if (lyrTbl.Has(cleanName))
                {
                    return(true);
                }
                else
                {
                    lyrTbl.UpgradeOpen();
                    var _layer = new AcadDb.LayerTableRecord();

                    // Assign the layer properties
                    _layer.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByColor, 7); // white
                    _layer.Name  = cleanName;

                    // Append the new layer to the layer table and the transaction
                    lyrTbl.Add(_layer);
                    tr.AddNewlyCreatedDBObject(_layer, true);
                }
            }
            catch { return(false); }
            return(true);
        }
        public override List <ISelectionFilter> GetSelectionFilters()
        {
            var layers = new List <string>();

            using (AcadDb.Transaction tr = Doc.Database.TransactionManager.StartTransaction())
            {
                AcadDb.LayerTable lyrTbl = tr.GetObject(Doc.Database.LayerTableId, AcadDb.OpenMode.ForRead) as AcadDb.LayerTable;
                foreach (AcadDb.ObjectId objId in lyrTbl)
                {
                    AcadDb.LayerTableRecord lyrTblRec = tr.GetObject(objId, AcadDb.OpenMode.ForRead) as AcadDb.LayerTableRecord;
                    layers.Add(lyrTblRec.Name);
                }
                tr.Commit();
            }
            return(new List <ISelectionFilter>()
            {
                new ListSelectionFilter {
                    Name = "Layers", Icon = "Filter", Description = "Selects objects based on their layers.", Values = layers
                }
            });
        }