4 Replies Latest reply on Nov 19, 2013 9:16 PM by FW Khor

    Macro to delete selected layers in SW Drawings.

    FW Khor

      Hi all,

       

      Im working on a macro to delete a selected layer in Layers window. The selected layer will be flag/marked by the "On/Off" lightbulb to toggle the visibility in drawing.

       

      To summarize:

       

      Visble (light bulb on) = Layers to be use/keep

      Invisible (light bulb of)  = Layers to purge/delete

       

      So the macro will delete all the layer that is invisible, while remain the visible intact.

       

      I already found a macro that delete all the layers:-

       

      Sub main()

          Dim swApp As SldWorks.SldWorks

          Dim doc As ModelDoc2

          Dim lyrMgr As LayerMgr

          Dim v As Variant

          Dim i As Integer

          Dim count As Integer

          Set swApp = Application.SldWorks

          Set doc = swApp.ActiveDoc

          Set lyrMgr = doc.GetLayerManager

          count = lyrMgr.GetCount

          v = lyrMgr.GetLayerList

          For i = 1 To count - 1

              lyrMgr.DeleteLayer (v(i))

          Next i

      End Sub

       

      Original link: http://compgroups.net/comp.cad.solidworks/macro-how-to-delete-layers/98701

       

      I need some help to implement the condition that I want to that macro.

       

      Thanks.