Use the SaveLayerState method to save a set of layer settings in a drawing. The SaveLayerState method requires three parameters. The first parameter is a string naming the layer state you are saving. The second parameter identifies the layer properties you want to save. Use the constants of the LayerStateMasks enum to identify the layer settings you want to save. The following table lists the constants that are part of the LayerStateMasks enum.
Add the constants together to specify multiple properties.
The third parameter required is the object id of the viewport whose layer settings you want to save. Use ObjectId.Null to not specify a viewport. If you try to save a layer state under a name that already exists, an error is returned. You must rename or delete the existing layer state before you can reuse the name.
Save a layer's color and linetype settings
The following code saves the color and linetype settings of the current layers in the drawing under the name ColorLinetype.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("SaveLayerColorAndLinetype")> _
Public Sub SaveLayerColorAndLinetype()
'' Get the current document
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acLyrStMan As LayerStateManager
acLyrStMan = acDoc.Database.LayerStateManager
Dim sLyrStName As String = "ColorLinetype"
If acLyrStMan.HasLayerState(sLyrStName) = False Then
acLyrStMan.SaveLayerState(sLyrStName, _
LayerStateMasks.Color + _
LayerStateMasks.LineType, _
ObjectId.Null)
End If
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("SaveLayerColorAndLinetype")]
public static void SaveLayerColorAndLinetype()
{
// Get the current document
Document acDoc = Application.DocumentManager.MdiActiveDocument;
LayerStateManager acLyrStMan;
acLyrStMan = acDoc.Database.LayerStateManager;
string sLyrStName = "ColorLinetype";
if (acLyrStMan.HasLayerState(sLyrStName) == false)
{
acLyrStMan.SaveLayerState(sLyrStName,
LayerStateMasks.Color |
LayerStateMasks.LineType,
ObjectId.Null);
}
}