Can anyone help to create a macro for drawing files that will check if a specific layer is visible, and if it is visible, hide the layer. Then I need to macro to print the drawing & close without saving.
When our company creates a drawing package for our customers we provide a print for most of the sub-assemblies and top level assemblies within the system (typically around 200-300 drawings per customer). These prints need to be dimensionless. So, in all of our drawing templates I have created a layer named "Dimension" where all of the dimensions reside. I found exactly what I need to turn the layer on/off from the API help (see below), but I'm not sure how to incorporate the print and 'no save' portion of the macro.
I have 0 programming experience, so I'm kind of lost here.
Sample code:
'------------------------------------
'
' Preconditions:
' (1) Drawing document is open.
' (2) Drawing document contains a layer named Dimension.
'
' Postconditions:
' If Dimension layer is visible, then it becomes not visible.
' - or -
' If Dimension 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("Dimension")
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
'------------------------------------
SolidworksApi macros