画層をフリーズ/フリーズ解除する(.NET)

画層をフリーズすると、表示の更新速度を速くしてオブジェクトの選択処理が向上し、複雑な図面の再描画時間を短縮できます。フリーズした画層上のオブジェクトは表示、印刷、または再作図されません。長期間使用しない画層をフリーズします。画層を「フリーズ解除」すると、AutoCAD はその画層上のオブジェクトを再描画して表示します。

画層をフリーズまたはフリーズ解除するには、IsFrozen プロパティを使用します。TRUE を入力すると、その画層はフリーズされます。FALSE を入力すると、画層はフリーズ解除されます。

画層をフリーズする

次の例は、"ABC" という新しい画層を作成し、次にその画層をフリーズします。

C# の例

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 
[CommandMethod("FreezeLayer")]
public static void FreezeLayer()
{
    // 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;

                // Freeze the layer
                acLyrTblRec.IsFrozen = 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;

            // Freeze the layer
            acLyrTblRec.IsFrozen = true;
        }

        // Save the changes and dispose of the transaction
        acTrans.Commit();
    }
}