您可以导出和输入保存的图层状态,以便在其他图形中使用相同的图层设置。使用该方法将保存的图层状态导出到 LAS 文件;使用该方法将 LAS 文件输入到工程图中。ExportLayerStateImportLayerState 注意:导入图层状态不会恢复它们;导入图层后,必须使用该方法恢复图层状态。RestoreLayerState
该方法接受两个参数。第一个参数是一个字符串,用于标识要导出的已保存图层状态。第二个参数是要将图层状态导出到的文件的名称。如果未指定文件的路径,则该文件将保存在打开图形的同一目录中。如果指定的文件名已存在,则将覆盖现有文件。使用 .命名文件时的 LAS 扩展名;这是AutoCAD为导出的图层状态文件识别的扩展名。ExportLayerState 该方法接受一个参数:一个字符串,用于命名包含要导入的图层状态的文件。如果要输入的图层状态不存在于 LAS 文件中,而是存在于图形文件中。可以打开图形文件,然后使用该方法从另一个图形的 Database 对象导入图层状态。ImportLayerStateImportLayerStateFromDb 导入图层状态时,如果保存设置中引用的任何特性在要输入到的图形中不可用,则会引发错误条件。但是,导入已完成,并使用默认属性。例如,如果导出的图层设置为未加载到要输入到的图形中的线型,则会引发错误条件,并替换图形的默认线型。您的代码应考虑此错误情况,并在引发此错误时继续处理。 如果输入的文件定义了当前图形中不存在的图层的设置,则将在当前图形中创建这些图层。使用该方法时,保存设置时指定的属性将分配给新图层;新图层的所有其他属性都分配了默认设置。RestoreLayerState 导出保存的图层设置以下示例将保存的图层状态导出到名为 ColorLinetype.las 的文件中。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("ExportLayerState")> _ Public Sub ExportLayerState() '' 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.ExportLayerState(sLyrStName, "c:\my documents\" & _ sLyrStName & ".las") End If End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("ExportLayerState")] public static void ExportLayerState() { // Get the current document Document acDoc = Application.DocumentManager.MdiActiveDocument; LayerStateManager acLyrStMan; acLyrStMan = acDoc.Database.LayerStateManager; string sLyrStName = "ColorLinetype"; if (acLyrStMan.HasLayerState(sLyrStName) == true) { acLyrStMan.ExportLayerState(sLyrStName, "c:\\my documents\\" + sLyrStName + ".las"); } } VBA/ActiveX 代码参考Sub ExportLayerStates()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.24")
oLSM.SetDatabase ThisDrawing.Database
oLSM.Export "ColorLinetype", "c:\my documents\ColorLinetype.las"
End Sub
导入保存的图层设置以下示例从名为 ColorLinetype.las 的文件中导入图层状态。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("ImportLayerState")> _ Public Sub ImportLayerState() '' Get the current document Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acLyrStMan As LayerStateManager acLyrStMan = acDoc.Database.LayerStateManager Dim sLyrStFileName As String = "c:\my documents\ColorLinetype.las" If System.IO.File.Exists(sLyrStFileName) Then Try acLyrStMan.ImportLayerState(sLyrStFileName) Catch ex As Autodesk.AutoCAD.Runtime.Exception Application.ShowAlertDialog(ex.Message) End Try End If End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("ImportLayerState")] public static void ImportLayerState() { // Get the current document Document acDoc = Application.DocumentManager.MdiActiveDocument; LayerStateManager acLyrStMan; acLyrStMan = acDoc.Database.LayerStateManager; string sLyrStFileName = "c:\\my documents\\ColorLinetype.las"; if (System.IO.File.Exists(sLyrStFileName)) { try { acLyrStMan.ImportLayerState(sLyrStFileName); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Application.ShowAlertDialog(ex.Message); } } } VBA/ActiveX 代码参考Sub ImportLayerStates()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.24")
oLSM.SetDatabase ThisDrawing.Database
' If the drawing you're importing to does not contain
' all the linetypes referenced in the saved settings,
' an error is returned. The import is completed, though,
' and the default linetype is used.
On Error Resume Next
oLSM.Import "c:\my documents\ColorLType.las"
If Err.Number = -2145386359 Then
' Error indicates a linetype is not defined
MsgBox ("One or more linetypes specified in the imported " + _
"settings is not defined in your drawing")
End If
On Error GoTo 0
End Sub
|
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:18
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.