Turn Layer Visibility On and Off Example (VBA)
This examples shows how to turn the visibility of a layer on and off.
'------------------------------------
'
' Preconditions:
' (1)
Drawing document is open.
' (2)
Drawing document contains a layer named NOTES.
'
' Postconditions:
' If
NOTES layer is visible, then it becomes not visible.
' -
or -
' If
NOTES layer is not visible, then it becomes visible.
'
'------------------------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swLayerMgr As
SldWorks.LayerMgr
Dim
swLayer As
SldWorks.Layer
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swLayerMgr = swModel.GetLayerManager
Set
swLayer = swLayerMgr.GetLayer("NOTES")
If
swLayer.Visible = False Then
'
Toggle layer on
swLayer.Visible = True
Debug.Assert
True = swLayer.Visible
Else
'
Toggle layer off
swLayer.Visible = False
Debug.Assert
False = swLayer.Visible
End
If
End Sub
'------------------------------------