Macro, how to delete layers?

Discussion in 'SolidWorks' started by Sam, Aug 23, 2007.

  1. Sam

    Sam Guest

    Anyone have a macro to delete either all layers in a drawing or a
    given layer by name? I tried using the example from the sw api help
    file but I kept getting an error. I think I would like to add this
    code to my existing "silent save" macro that is assigned to hotkey S.



    Thanks,

    Sam
     
    Sam, Aug 23, 2007
    #1
  2. Sam

    niceguy Guest

    Here's one way to delete them all:

    ========================
    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
    ====================
     
    niceguy, Aug 23, 2007
    #2
  3. Sam

    Sam Guest

    Thanks, that worked. I will see if I can tweak it only delete certain
    layers. Maybe what I want is to not delete layers whose visibility is
    set to Off, because I do not want whatever is on those hidden layers
    to be visible.

    Your macro gives me a great start.

    Thanks
     
    Sam, Aug 23, 2007
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.