Locking the layer through .NET

By Virupaksha Aithal

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();
}

Comments

3 responses to “Locking the layer through .NET”

  1. petcon Avatar
    petcon

    rset the line weight Just make layer dirty..
    i do not understand what this mean

  2. tiancao1001 Avatar
    tiancao1001

    rset the line weight Just make layer dirty..
    是什么意思,好像也没起什么作业?是系统变量LAYLOCKFADECTL的淡入度吗?

  3. tiancao1001 Avatar
    tiancao1001

    应该就是 LAYLOCKFADECTL 变量 相同的意思

Leave a Reply to tiancao1001Cancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading