1 つの画層を現在の画層にする(.NET)

図形は常にアクティブな画層上に描かれます。画層をアクティブにすると、新規オブジェクトはその画層上に作成されます。別の画層をアクティブにすると、作成する新規オブジェクトには新たにアクティブにした画層が割り当てられ、その色と線種が使用されます。フリーズした画層は、アクティブにできません。

画層をアクティブにするには、Database オブジェクトの Clayer プロパティを使用するか、システム変数 CLAYER を使用します。次に例を示します。

データベースを使用して画層を現在の画層に設定する

この例では、Database オブジェクトの Clayer プロパティを使用して画層を現在の画層に設定します。

C# の例

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

        if (acLyrTbl.Has(sLayerName) == true)
        {
            // Set the layer Center current
            acCurDb.Clayer = acLyrTbl[sLayerName];

            // Save the changes
            acTrans.Commit();
        }

        // Dispose of the transaction
    }
}

システム変数 CLAYER を使用して画層を現在の画層に設定する

この例では、システム変数 CLAYER を使用して画層を現在の画層に設定します。

C# の例

Application.SetSystemVariable("CLAYER", "Center");