Macro, how to delete layers?

Aug 23, 2007 2 Replies

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



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 ====================

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required