You can export and import saved layer settings to use those settings in other drawings. Use the LayerStateManager's Export method to save layer settings to a file; use the Import method to import saved layer settings into a drawing.
The Export method accepts two parameters. The first parameter is a string identifying the saved layer settings you are exporting. The second parameter is the name of the file you are exporting the settings to. If you do not specify a path for the file, it is saved in the AutoCAD installation directory. 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 setting files.
The Import method accepts one parameter: a string naming the file that contains the layer settings you are importing.
When you are importing layer settings, an error condition is raised if any properties referenced in the saved settings are not available in the drawing you're 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 Restore 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.
The following code exports saved layer settings to a file named Colortype.las.
Sub Ch4_ExportLayerSettings()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")
oLSM.SetDatabase ThisDrawing.Database
oLSM.Export "ColorLinetype", "c:\my documents\ColorLType.las"
End Sub
The following code imports layer settings from a file named Colortype.las.
Sub Ch4_ImportLayerSettings()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")
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