该方法将图层设置重置为图层状态,并且需要四个值。第一个值是要还原的图层状态的名称,第二个值是要还原其图层设置的视口的对象 ID。第三个值是一个整数,用于定义如何处理未处于图层状态的图层。第四个值确定要恢复的图层设置。RestoreLayerState 以下值确定如何处理未处于图层状态的图层:
注意:您可以使用前面列出的多个值的总和来定义未处于图层状态的图层的恢复行为。例如,您可以关闭并冻结未使用图层状态保存的图层。
例如,如果将颜色和线型设置保存在名称“ColorLinetype”下,然后更改这些设置,则还原“ColorLinetype”会将图层重置为保存“ColorLinetype”时的颜色和线型。如果在保存“ColorLinetype”后向图形添加新图层,则在恢复“ColorLinetype”时,这些新图层不受影响。 恢复图形图层的颜色和线型设置假设当前图形中图层的颜色和线型设置以前保存在名称“ColorLinetype”下,则以下代码将图形中每个图层的颜色和线型设置恢复到保存“ColorLinetype”时的值。 VB.NETImports 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 C#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); } } VBA/ActiveX 代码参考Sub RestoreLayerState()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.24")
oLSM.SetDatabase ThisDrawing.Database
oLSM.Restore "ColorLinetype"
End Sub
|
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:49
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.