ロックされた画層のオブジェクトは編集できませんが、画層がオンになっていてフリーズが解除されていれば、表示されています。ロックされた画層を現在の画層にすると、そこにオブジェクトを追加できます。ロックされた画層は、フリーズおよびフリーズ解除でき、画層に割り当てられた色と線種を変更することもできます。
画層をロックまたはロック解除するには、IsLocked プロパティを使用します。TRUE を入力すると、その画層はロックされます。FALSE を入力すると、その画層はロック解除されます。
次の例は、"ABC" という新しい画層を作成し、次にその画層をロックします。
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("LockLayer")]
public static void LockLayer()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Layer table for read
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
string sLayerName = "ABC";
if (acLyrTbl.Has(sLayerName) == false)
{
using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
{
// Assign the layer a name
acLyrTblRec.Name = sLayerName;
// Lock the layer
acLyrTblRec.IsLocked = true;
// Upgrade the Layer table for write
acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite);
// Append the new layer to the Layer table and the transaction
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
}
}
else
{
LayerTableRecord acLyrTblRec = acTrans.GetObject(acLyrTbl[sLayerName],
OpenMode.ForWrite) as LayerTableRecord;
// Lock the layer
acLyrTblRec.IsLocked = true;
}
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}