図形は常にアクティブな画層上に描かれます。画層をアクティブにすると、新規オブジェクトはその画層上に作成されます。別の画層をアクティブにすると、作成する新規オブジェクトには新たにアクティブにした画層が割り当てられ、その色と線種が使用されます。フリーズした画層は、アクティブにできません。
画層をアクティブにするには、Database オブジェクトの Clayer プロパティを使用するか、システム変数 CLAYER を使用します。例:
この例では、Database オブジェクトの Clayer プロパティを使用して画層を現在の画層に設定します。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("SetLayerCurrent")> _
Public Sub SetLayerCurrent()
'' Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Layer table for read
Dim acLyrTbl As LayerTable
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
Dim sLayerName As String = "Center"
If acLyrTbl.Has(sLayerName) = True Then
'' Set the layer Center current
acCurDb.Clayer = acLyrTbl(sLayerName)
'' Save the changes
acTrans.Commit()
End If
'' Dispose of the transaction
End Using
End Sub
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
}
}
ThisDrawing.ActiveLayer = ThisDrawing.Layers("Center")
この例では、システム変数 CLAYER を使用して画層を現在の画層に設定します。
Application.SetSystemVariable("CLAYER", "Center")
Application.SetSystemVariable("CLAYER", "Center");
ThisDrawing.SetVariable "CLAYER", "Center"