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.
使用 SaveLayerState 方法保存图形中的图层设置。SaveLayerState 方法接受三个参数。第一个参数是字符串,指定保存的图层状态的名称;第二个参数标识要保存的图层属性。请使用 LayerStateMasks 枚举常量来标识要保存的图层设置。下表列出了 LayerStateMasks 枚举常量的内容。
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.
第三个参数需要你想将图层设置保存到的那个视口的 ObjectID。若没有指定视口,请使用 ObjectID.Null。如果使用已有的名称保存图层状态,将返回错误。必须先重命名或删除现有的保存的图层状态,才能重新使用该名称。
The following code saves the color and linetype settings of the current layers in the drawing under the name ColorLinetype.
以下代码以 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);
}
}