You can export and import saved layer states to use the same layer settings in other drawings. Use the ExportLayerState method to export a saved layer state to an LAS file; use the ImportLayerState method to import a LAS file into a drawing.
用户可以输出和输入图层的设置,以便在其他图形中使用这些设置。使用 ExportLayerState 方法输出一个已保存的图层状态到一个 LAS 文件中;使用 ImportLayerState 方法从一个 LAS 文件输入到图形中。
NoteImporting layer states does not restore them; you must use the RestoreLayerState method to restore the layer state after it is imported.
注意输入图层设置并不会恢复这些状态。必须使用 RestoreLayerState 方法将图形中的图层状态为输入的设置。
The ExportLayerState method accepts two parameters. The first parameter is a string identifying the saved layer state to export. The second parameter is the name of the file you are exporting the layer state to. If you do not specify a path for the file, it is saved in the same directory in which the drawing was opened from. If the file name you specified already exists, the existing file is overwritten. Use a .las extension when naming files; this is the extension AutoCAD recognizes for exported layer state files.
ExportLayerState 方法接受两个参数。第一个参数是一个字符串,标识用户输出的保存的图层状态;第二个参数是接受输出设置的文件名称。如果用户不指定文件的路径,文件将保存到 与打开的图形文件相同的目录中。如果用户指定的文件名称已经存在,则现有的文件将被替换。命名文件时请使用 .las 扩展名,这是 AutoCAD 能够识别的输出图层状态文件的扩展名。
The ImportLayerState method accepts one parameter: a string naming the file that contains the layer states you are importing. If the layer state you want to import does not exist in a LAS file, but a drawing file. You can open the drawing file and then use the ImportLayerStateFromDb method to import a layer state from the Database object of the other drawing.
ImportLayerState 方法接受一个参数:一个字符串,用于命名包含用户输入的图层设置的文件。 如果你想输入的图层状态不是保存在 LAS 文件中,而是在一个图形文件中。你可以先打开图形文件,然后使用 ImportLayerStateFromDb 方法从另外一个图形的 Database 对象中输入图层状态。
When you import layer states, an error condition is raised if any properties referenced in the saved settings are not available in the drawing you are importing to. The import is completed, however, and default properties are used. For example, if an exported layer is set to a linetype that is not loaded in the drawing it is being imported into, an error condition is raised and the drawing's default linetype is substituted. Your code should account for this error condition and continue processing if it is raised.
在输入图层设置时,如果已保存设置中引用的任何特性不存在于要输入设置的图形中,将出现错误。但输入会使用默认的特性完成。例如,如果输出的图层设置为使用未在要输入该图层的图形中加载的线型,将产生错误,并将使用图形的默认线型对其进行替换。用户的代码应该记录这种错误条件,以便在产生错误时能够继续处理。
If the imported file defines settings for layers that do not exist in the current drawing, those layers are created in the current drawing. When you use the RestoreLayerState method, the properties specified when the settings were saved are assigned to the new layers; all other properties of the new layers are assigned default settings.
如果当前图形中不存在输入文件定义的图层设置,将在当前图形中创建这些图层。使用 RestoreLayerState 方法时,在保存设置时指定的特性将被指定到新图层,而新图层的其他所有特性都使用默认设置。
The following example exports a saved layer state to a file named ColorLinetype.las.
以下代码将保存的图层设置输出到名为 ColorLinetype.las 的文件中。
Imports 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
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");
}
}
The following example imports the layer state from a file named ColorLinetype.las.
以下代码从名为 ColorLinetype.las 文件输入图层设置。
Imports 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
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);
}
}
}