The RestoreLayerState method resets the layer settings in a layer state and requires four values. The first value is the name of the layer state to restore, and the second value is the object id of the viewport whose layer settings you want to restore. The third value is an integer that defines how layers not in the layer state are handled. The fourth value determines which layer settings are restored.
RestoreLayerState 方法重设图层设置到一个图层状态和需要的四个值。第一个值是要恢复的图层状态的名字,第二个值是你想恢复图层设置到那个视口的 ObjectID。第三个值是一个整数值,它确定如何处理在图层状态中没有的图层。第四个值确定哪些图层设置将被恢复。
The following values determine how layers not in a layer state are handled:
下列值确定如何处理在图层状态中没有的图层:
NoteYou can use the sum of multiple values previous listed to define the restore behavior of layers not in a layer state. For example, you can turn off and freeze the layers that are not saved with a layer state.
注意用户可以使用多个前面列出的值的和来定义没有在图层状态中的图层的恢复行为。例如,可以关闭并冻结没有保存在图层状态中的图层。
For example, if you save the color and linetype settings under the name “ColorLinetype” and subsequently change those settings, restoring “ColorLinetype” resets the layers to the colors and linetypes they had when “ColorLinetype” was saved. If you add new layers to the drawing after saving “ColorLinetype,” those new layers are not affected when you restore “ColorLinetype.”
例如,如果你以名字“ColorLineType”保存了颜色和线型设置,然后修改了这些设置,恢复“ColorLineType”中保存的设置以重设图层的颜色和线型。如果添加新的图层到图形后再保存“ColorLineType”,新图层将不会影响你恢复“ColorLineType”。
Assuming that the color and linetype settings of the layers in the current drawing were previously saved under the name “ColorLinetype,” the following code restores the color and linetype settings of each layer in the drawing to the value they had when “ColorLinetype” was saved.
假设当前图形中图层的颜色和线型设置先前被保存在名称“ColorLinetype”下,以下代码将把图形中每个图层的颜色和线型都重置为保存“ColorLinetype”时这些设置具有的值。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("RestoreLayerState")> _
Public Sub RestoreLayerState()
'' 获得当前文档 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) = True Then
acLyrStMan.RestoreLayerState(sLyrStName, _
ObjectId.Null, _
1, _
LayerStateMasks.Color + _
LayerStateMasks.LineType)
End If
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("RestoreLayerState")]
public static void RestoreLayerState()
{
// 获得当前文档 Get the current document
Document acDoc = Application.DocumentManager.MdiActiveDocument;
LayerStateManager acLyrStMan;
acLyrStMan = acDoc.Database.LayerStateManager;
string sLyrStName = "ColorLinetype";
if (acLyrStMan.HasLayerState(sLyrStName) == true)
{
acLyrStMan.RestoreLayerState(sLyrStName,
ObjectId.Null,
1,
LayerStateMasks.Color |
LayerStateMasks.LineType);
}
}