AnsweredAssumed Answered

Macro - toggle both layer + document setting on/off

Question asked by Peter Larsen on Sep 9, 2014
Latest reply on Sep 9, 2014 by Peter Larsen

Hello everyone,

 

I am trying to create a macro that toggles 2 things at the same time on a SW drawing:

  1. Turn on/off a specific layer
  2. Turn on/off the document setting shown below.

 

I found a macro here on the forum that toggles the layer (shown below) but how do I add the on/off toggle of the document setting?

I am not familar with macros but hoping to learn more about later on.

 

Thank you in advance.

 

Regards

Peter

 

 

Dim swApp As Object

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("Variant_Controlled")

  

    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

Set swApp = Application.SldWorks

End Sub

Outcomes