- 积分
- 12459
- 明经币
- 个
- 注册时间
- 2003-5-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
<BR>ublic g_LayerInfoArray() As LayerInfoObj
'-----------------------------------------------------------------------------
Type LayerInfoObj<BR> layerObj As AcadLayer<BR> layerName As String<BR> isOn As Boolean<BR> isLock As Boolean<BR> isFreeze As Boolean<BR>End Type
'----保存所有图层状态-------------------------------------------------------------------------
Public Sub GetLayerInfoArray()<BR> On Error GoTo ErrorHandler<BR> ReDim g_LayerInfoArray(0)<BR> <BR> Dim lay As AcadLayer<BR> Dim lays As AcadLayers<BR> Set lays = ThisDrawing.Layers<BR> <BR> Dim i As Integer<BR> <BR> For i = 0 To lays.count - 1<BR> Set lay = lays.Item(i)<BR> ReDim Preserve g_LayerInfoArray(UBound(g_LayerInfoArray) + 1)<BR> <BR> With g_LayerInfoArray(UBound(g_LayerInfoArray))<BR> Set .layerObj = lay<BR> .layerName = lay.name<BR> .isOn = lay.LayerOn<BR> .isLock = lay.Lock<BR> .isFreeze = lay.Freeze<BR> End With<BR> Next<BR> <BR> Exit Sub<BR>ErrorHandler:<BR> Debug.Print "Sub GetLayerInfoArray() occurs errors: " + Err.Description<BR>End Sub
'----恢复所有图层状态-----------------------------------------------------
Public Sub SetLayerInfoArray()<BR> On Error GoTo ErrorHandler<BR> <BR> Dim i As Integer<BR> Dim lay As AcadLayer<BR> <BR> For i = 1 To UBound(g_LayerInfoArray)<BR> Set lay = g_LayerInfoArray(i).layerObj<BR> If LayerExist(lay.name) Then<BR> With lay<BR> .LayerOn = g_LayerInfoArray(i).isOn<BR> .Lock = g_LayerInfoArray(i).isLock<BR> If IsCurrentLayer(lay.name) = False Then<BR> .Freeze = g_LayerInfoArray(i).isFreeze<BR> End If<BR> End With<BR> End If<BR> Next<BR> <BR> Exit Sub<BR>ErrorHandler:<BR> Debug.Print "Sub SetLayerInfoArray() occurs errors: " + Err.Description<BR>End Sub
Public Sub ClearLayerInfoArray()<BR> ReDim g_LayerInfoArray(0)<BR>End Sub
'-----------------------------------------------------------------------------<BR>'-----------------------------------------------------------------------------
Public Function LayerExist(ByVal layerName As String) As Boolean<BR> On Error GoTo ErrorHandler<BR> LayerExist = False<BR> <BR> Dim layerObj As AcadLayer<BR> Set layerObj = ThisDrawing.Layers.Item(layerName)<BR> <BR> LayerExist = True<BR> <BR> Exit Function<BR>ErrorHandler:<BR>End Function
Public Function IsCurrentLayer(ByVal layerName As String) As Boolean<BR> Dim sysVarName As String<BR> Dim varData As Variant<BR> <BR> sysVarName = "CLAYER"<BR> varData = ThisDrawing.GetVariable(sysVarName)<BR> <BR> If StrComp(UCase$(varData), UCase(layerName)) = 0 Then<BR> IsCurrentLayer = True<BR> Else<BR> IsCurrentLayer = False<BR> End If<BR> <BR>End Function
Public Sub CloseAllLayers()<BR> On Error GoTo ErrorHandler<BR> <BR> Dim layerObj As AcadLayer<BR> Dim layersObj As AcadLayers<BR> Set layersObj = ThisDrawing.Layers<BR> <BR> Dim i As Integer<BR> For i = 0 To layersObj.count - 1<BR> Set layerObj = layersObj.Item(i)<BR> layerObj.LayerOn = False<BR> Next<BR> <BR> Exit Sub<BR>ErrorHandler:<BR>End Sub
Public Sub OpenLayer(ByVal layerName As String, ByVal bOnOff As Boolean)<BR> On Error GoTo ErrorHandler<BR> If LayerExist(layerName) Then<BR> Dim layerObj As AcadLayer<BR> Set layerObj = ThisDrawing.Layers.Item(layName)<BR> layerObj.LayerOn = bOnOff<BR> End If<BR> <BR> Exit Sub<BR>ErrorHandler:<BR>End Sub
Public Sub LockLayer(ByVal layerName As String, ByVal bLock As Boolean)<BR> On Error GoTo ErrorHandler<BR> If LayerExist(layerName) Then<BR> Dim layerObj As AcadLayer<BR> Set layerObj = ThisDrawing.Layers.Item(layName)<BR> layerObj.Lock = bLock<BR> End If<BR> <BR> Exit Sub<BR>ErrorHandler:<BR>End Sub
Public Sub FreezeLayer(ByVal layerName As String, ByVal bFreeze As Boolean)<BR> On Error GoTo ErrorHandler<BR> If LayerExist(layerName) Then<BR> Dim layerObj As AcadLayer<BR> Set layerObj = ThisDrawing.Layers.Item(layName)<BR> layerObj.Lock = bFreeze<BR> End If<BR> <BR> Exit Sub<BR>ErrorHandler:<BR>End Sub
Public Sub SetClayer(ByVal layerName As String)<BR> If IsCurrentLayer(layerName) = False And LayerExist(layerName) Then<BR> Dim sysVarName As String<BR> Dim sysVarData As Variant<BR> <BR> sysVarName = "CLAYER"<BR> sysVarData = layerName<BR> ThisDrawing.SetVariable sysVarName, sysVarData<BR> End If<BR>End Sub<BR> |
|