Save Layer Settings

AutoCAD ActiveX

 
Save Layer Settings
 
 
 

Use the Save method to save a set of layer settings in a drawing. The Save method accepts two parameters. The first parameter is a string naming the layer settings you are saving. The second parameter identifies the layer properties you want to save. Use the constants in the following table to identify layer properties.

Constants for layer properties

Constant name

Layer property

acLsAll

All layer settings

acLsColor

Color

acLsFrozen

Frozen or thawed

acLsLineType

Linetype

acLsLineWeight

Lineweight

acLsLocked

Locked or unlocked

acLsNewViewport

New viewport layers frozen or thawed

acLsNone

None

acLsOn

On or off

acLsPlot

Plotting on or off

acLsPlotStyle

Plot style

Add the constants together to specify multiple properties.

If you try to save layer settings under a name that already exists, an error is returned. You must rename or delete the existing saved layer settings before you can reuse the name.

Save a layer's color and linetype settings

The following code saves the color and linetype settings of the current layer under the name ColorLinetype.

Sub Ch4_SaveLayerColorAndLinetype()
    Dim oLSM As AcadLayerStateManager
    ' Access the LayerStateManager object
    Set oLSM = ThisDrawing.Application. _
       GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")
    ' Associate the current drawing database with LayerStateManager
    oLSM.SetDatabase ThisDrawing.Database
    oLSM.Save "ColorLinetype", acLsColor + acLsLineType
End Sub

Rename a saved layer setting

The following code renames the ColorLinetype layer settings to OldColorLinetype.

Sub Ch4_RenameLayerSettings()
    Dim oLSM As AcadLayerStateManager
    Set oLSM = ThisDrawing.Application. _
       GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")
    oLSM.SetDatabase ThisDrawing.Database
    oLSM.Rename "ColorLinetype", "OldColorLinetype"
End Sub

Delete a saved layer setting

The following code deletes layer settings that were saved under the name ColorLinetype.

Sub Ch4_DeleteColorAndLinetype()
    Dim oLSM As AcadLayerStateManager
    Set oLSM = ThisDrawing.Application. _
       GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")
    oLSM.SetDatabase ThisDrawing.Database
    oLSM.Delete "ColorLinetype"
End Sub