Macro, how to delete layers?

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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 ==================
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.