Is there a way to filter select all locked/unlocked layers

Is there a way to filter select all locked/unlocked layers

Anonymous
Not applicable
886 Views
1 Reply
Message 1 of 2

Is there a way to filter select all locked/unlocked layers

Anonymous
Not applicable

I have been started .net programming for my work to improve some process.
Is there an easy way to get filter select all locked or unlocked layers

ex.

Dim acTypValAr.(0) As TypeValue

acTypeValAr.setValue(New TypedValue(DxfCode.***, ***),0)

Dim acSelFtr as SelectionFilter = New SelectionFilter(acTypValAr)

 

I've seen dxf code reference but there is no such option.
I've thought of a another option of getting all the [Layerablerecord.name in Layertablerecord.islocked] then populate it in [dxfcode.layername, layertablerecordname] but havent tested it yet.

This is my first time posting in this community, I hope I will learn more, any thoughts will be a great help.

0 Likes
Accepted solutions (1)
887 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You have to iterate through the layer table to collect all locked layer names and then, use these names (comma separated) in your selection filter.

 

Here's a C# little example (you should learn C# instead of VB)

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var locked = new List<string>();
            using (var tr = new OpenCloseTransaction())
            {
                var layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                foreach (ObjectId id in layerTable)
                {
                    var layer = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
                    if (layer.IsLocked)
                        locked.Add(layer.Name);
                }
            }
            var filter = new SelectionFilter(new[] { new TypedValue(8, string.Join(",", locked)) });
            var result = ed.SelectAll(filter);
            if (result.Status == PromptStatus.OK)
                ed.SetImpliedSelection(result.Value);
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes