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

Reply to
Sam
Loading thread data ...

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

Reply to
niceguy

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

Reply to
Sam

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.