使用该方法在图形中保存一组图层设置。该方法需要三个参数。第一个参数是命名要保存的图层状态的字符串。第二个参数用于标识要保存的图层属性。使用枚举的常量来标识要保存的图层设置。下表列出了属于枚举的常量。SaveLayerStateSaveLayerStateLayerStateMasksLayerStateMasks
将常量相加以指定多个属性。 所需的第三个参数是要保存其图层设置的视口的对象 ID。用于不指定视口。如果尝试将图层状态保存在已存在的名称下,则会返回错误。必须先重命名或删除现有图层状态,然后才能重复使用该名称。ObjectId.Null 保存图层的颜色和线型设置以下代码将图形中当前图层的颜色和线型设置保存在名为 ColorLinetype 下。 VB.NETImports 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 C#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); } } VBA/ActiveX 代码参考Sub SaveLayerColorAndLinetype()
Dim oLSM As AcadLayerStateManager
' Access the LayerStateManager object
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.24")
' Associate the current drawing database with LayerStateManager
oLSM.SetDatabase ThisDrawing.Database
oLSM.Save "ColorLinetype", acLsColor + acLsLineType
End Sub
|
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:32
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.