Macro to set all CenterLine and CenterMark linestyle to "Center"

As of SW2025 SP3, Centerline linestyle will be “Solid” unless you set the option to put them on their own layer or manually change them after inserting them.

See Why Are My Centerlines Solid in SOLIDWORKS?

I made a macro that will go through every CenterLine (and CenterMark) in a drawing and set their linestyle to “Center”

Function ChangeCenterlinesToCenterStyle() As Boolean 'Mark Soldan 12/2025
’ Workaround for the SW2025 SP3 CenterMark linestyle regression
’ Forces all CenterLines and CenterMarks to use the “Center” linestyle in all views on all sheets.
Dim ThisProc As String: ThisProc = “ChangeCenterlinesToCenterStyle()”
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vSheetNames As Variant
Dim ActiveSheetName As String
Dim sSheetName As String
Dim nAnnotType As Long
Dim vViews As Variant
Dim swView As SldWorks.View
Dim vAnnotations As Variant
Dim swAnnotation As SldWorks.Annotation
Dim swCenterMark As SldWorks.CenterMark
Dim i As Long
Dim j As Long
Dim k As Long
Dim BoolStatus As Boolean

Debug.Print "== BEGIN " & ThisMacro & " / " & ThisProc
ChangeCenterlinesToCenterStyle = False

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
    Debug.Print "No active document. Please open a drawing."
    ChangeCenterlinesToCenterStyle = False
    Exit Function
End If

If swModel.GetType <> swDocDrawing Then
    Debug.Print "Active document is not a drawing."
    ChangeCenterlinesToCenterStyle = False
    Exit Function
End If

Set swDrawing = swModel

vSheetNames = swDrawing.GetSheetNames
If IsEmpty(vSheetNames) Then
    Debug.Print "No sheets found in the drawing."
    ChangeCenterlinesToCenterStyle = True
    Exit Function
End If

Set swSheet = swDrawing.GetCurrentSheet
ActiveSheetName = swSheet.GetName

For i = LBound(vSheetNames) To UBound(vSheetNames)
sSheetName = vSheetNames(i)
    Set swSheet = swDrawing.Sheet(sSheetName)
    If Not swSheet Is Nothing Then
        vViews = swSheet.GetViews
        If Not IsEmpty(vViews) Then
            For j = LBound(vViews) To UBound(vViews)
                Set swView = vViews(j)
                If Not swView Is Nothing Then
                    vAnnotations = swView.GetAnnotations
                    If Not IsEmpty(vAnnotations) Then
                        For k = LBound(vAnnotations) To UBound(vAnnotations)
                            Set swAnnotation = vAnnotations(k)
                            nAnnotType = swAnnotation.GetType
                            If nAnnotType = 15 Then 'This is a CenterLine
                                swModel.ClearSelection2 True
                                BoolStatus = swAnnotation.Select3(False, Nothing)
                                If BoolStatus Then
                                    swModel.SetLineStyle "CENTER"
                                End If
                            ElseIf nAnnotType = 13 Then 'This is a CenterMark
                                Set swCenterMark = swAnnotation.GetSpecificAnnotation
                                If Not swCenterMark Is Nothing Then
                                    swCenterMark.CenterLineFont = True
                                End If
                            End If
                            
                        Next k
                    End If
                End If
            Next j
        End If
    End If
Next i
swModel.ActivateSheet ActiveSheetName
swModel.ClearSelection2 True
swModel.ForceRebuild3 False
swModel.GraphicsRedraw2

ChangeCenterlinesToCenterStyle = True
Debug.Print "== DONE " & ThisMacro & " / " & ThisProc

End Function

3 Likes