2 Replies Latest reply on Apr 28, 2015 2:01 PM by Mike Sveda

    How to make a macro turn on/off a drawing layer?

    Mike Sveda

      I want to make a simple macro to turn on/off a layer in a drawing.  Can some share the code to do this?  I don't know VB.  Thanks

        • Re: How to make a macro turn on/off a drawing layer?
          Christopher Estelow

          You should be able to record the macro yourself.  Go to Tools - Macros - Record Macro then go to the layers toolbar and turn off the layer then click stop recording and save it.  You can do the opposite to turn it back on.  I'm not sure if it will work but it's worth a shot!!

           

          Chris

            • Re: How to make a macro turn on/off a drawing layer?
              Mike Sveda

              Ah found it

               

              ' Postconditions:

              '          If Customer layer is visible, then it becomes not visible.

              '             - or -

              '          If Customer 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("Customer")

                  

                  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