程序利用注册表来保存切换的图层配置,现在还未完成生成注册表部分,大家可以把以下文件导入到注册表中先试试吧:
注意以下程序下载:
以下是程序内容:
-
- ' AutoLayer.dvb
- Public EntCount As Integer
- Public LayerSet As Variant
- Public GetReg As Boolean
- Private Sub AutoLayerLoad()
- Dim LayerSetting() As String
- Dim SplitSetting As Variant
- Dim LayerName As Variant
- Dim LayerCount As Integer
- LayerName = GetAllSettings("MCCAD", "AutoLayer")
- For LayerCount = LBound(LayerName, 1) To UBound(LayerName, 1)
- ReDim Preserve LayerSetting(2, LayerCount)
- LayerSetting(0, LayerCount) = LayerName(LayerCount, 0)
- SplitSetting = Split(LayerName(LayerCount, 1), ",")
- LayerSetting(1, LayerCount) = SplitSetting(0)
- LayerSetting(2, LayerCount) = SplitSetting(1)
- Next
- LayerSet = LayerSetting()
- End Sub
- Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
- EntCount = ThisDrawing.ModelSpace.Count
- End Sub
- Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
- If GetReg = False Then
- AutoLayerLoad
- GetReg = True
- End If
- Dim NewEnt As AcadEntity
- Dim i As Integer
- Dim NewLayerName As String
- Dim j As Integer
- Dim NewLayerColor As Integer
- For j = LBound(LayerSet, 2) To UBound(LayerSet, 2)
- If UCase(CommandName) Like LayerSet(0, j) Then
- NewLayerName = LayerSet(1, j)
- NewLayerColor = CVar(LayerSet(2, j))
- CreateLayer NewLayerName, NewLayerColor
- If ThisDrawing.ModelSpace.Count > EntCount Then
- For i = EntCount To ThisDrawing.ModelSpace.Count - 1
- Set NewEnt = ThisDrawing.ModelSpace.Item(i)
- NewEnt.Layer = NewLayerName
- Next
- End If
- Exit For
- End If
- Next
- End Sub
- Public Function CreateLayer(ssLayerName As String, Optional EntColor As Integer) As AcadLayer
- On Error Resume Next
- Set CreateLayer = ThisDrawing.Layers(ssLayerName)
- If Err Then
- Err.Clear
- Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
- If EntColor 0 Then CreateLayer.color = EntColor
- End If
- End Function
|