Each layer (layer table record) exposes “IsLocked” property. You can set the “IsLocked” to true to lock the layer. Below code shows the procedure to so the same. Below code to work, there should be layer called “Test” in the document.
[CommandMethod("Layerlack")]
static public void Layerlack()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable table = tr.GetObject(db.LayerTableId,
OpenMode.ForRead) as LayerTable;
if (table.Has("Test"))
{
LayerTableRecord record = tr.GetObject(table["Test"],
OpenMode.ForWrite) as LayerTableRecord;
record.IsLocked = true;
//rset the line weight Just make layer dirty..
record.LineWeight = record.LineWeight;
}
tr.Commit();
}
ed.Regen();
}

Leave a Reply