MACRO LIBRARY

Change all layer colors

Free public access. No account or subscription required.

Files

Change all layer colors

Code

Module:

'Changes the color of drawing layers to black.
    
'Preconditions: Drawing is open.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As ModelDoc2
    Dim swLayerMgr As LayerMgr
    Dim swLayer As Layer
    Dim vLayerNames As Variant
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    If swModel Is Nothing Then Exit Sub
    If swModel.GetType <> swDocDRAWING Then Exit Sub
    
    Set swLayerMgr = swModel.GetLayerManager
    vLayerNames = swLayerMgr.GetLayerList
    
    If IsEmpty(vLayerNames) Then
        MsgBox "Drawing contains zero layers."
        Exit Sub
    End If
    
    For i = 0 To UBound(vLayerNames)
        Set swLayer = swLayerMgr.GetLayer(vLayerNames(i))
        swLayer.Color = RGB(0, 0, 0)
    Next i
End Sub