You are always drawing on the active layer. When you make a layer active, you create new objects on that layer. If you make a different layer active, any new objects you create is assigned that new active layer and uses its color and linetype. You cannot make a layer active if it is frozen.
To make a layer active, use the Clayer property of the Database object or the CLAYER system variable. For example:
Make a layer current through the database
This example sets a layer current through the Database object with the Clayer property.
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
}
}
Make a layer current with the CLAYER system variable
This example sets a layer current with the CLAYER system variable.