US$0.00
0

SOLIDWORKS Macro for Reloading Sheet Formats in Drawing Documents

Description

The SolidWorks macro for reloading sheet formats in drawing documents automates the process of refreshing and standardizing sheet templates across all sheets in a SOLIDWORKS drawing. It iterates through each sheet, temporarily removes the current format, and then reloads the original template. This macro ensures every sheet is updated with the correct default format, rebuilding and saving the document automatically to simplify drawing maintenance and formatting consistency.

SOLIDWORKS Macro for Reloading Sheet Formats in Drawing Documents and A side-by-side comparison labeled "BEFORE" and "AFTER" in a SOLIDWORKS drawing sheet with an A-size border. The "BEFORE" section shows a blank sheet with a large circle centered on it, intersected by horizontal and vertical centerlines, and an empty title block at the bottom. The "AFTER" section displays the same circle and sheet, but a pop-up dialog box in the center reads "SOLIDWORKS" at the top, "Sheet format reloaded!" in the middle, and an "OK" button highlighted in blue. The title block is now fully populated with standard fields such as company name, drawing title, and revision table, and a macro button labeled "Reload_All_Sheet_Formats" appears at the bottom right, indicating the sheet format has been successfully reloaded.

System Requirements

  • SolidWorks Version: SolidWorks 2014 or newer
  • Operating System: Windows 10 or later
  • Excel Version: Microsoft Excel 2010 or later (for Excel integration features)

Pre-Conditions

  • SolidWorks must be installed and running on the machine.
  • An active drawing is open.

Post-Conditions

  • The macro will first remove the existing sheet format and then reload the previous format from the specified location for each sheet.
  • Note: This may remove all content contained within the old/existing format.

VBA Macro Code

' Disclaimer:
' The code provided should be used at your own risk.  
' Blue Byte Systems Inc. assumes no responsibility for any issues or damages that may arise from using or modifying this code.  
' For more information, visit [Blue Byte Systems Inc.](https://bluebyte.biz).

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swSheet As SldWorks.Sheet
    Dim vSheetProps As Variant
    Dim vSheetName As Variant
    Dim vTemplateName As Variant

    Dim longstatus As Long
    Dim longwarnings As Long
    Dim nErrors As Long
    Dim nWarnings As Long
    Dim i As Long

    ' Initialize SolidWorks application
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    ' Check if an active drawing is open
    If swModel Is Nothing Then
        MsgBox "There is no active drawing document."
        Exit Sub
    End If
    
    ' Ensure the active document is a drawing
    If swModel.GetType <> swDocDRAWING Then
        MsgBox "Open a drawing first and then try again!"
        Exit Sub
    End If

    Set swDraw = swModel
    vSheetName = swDraw.GetSheetNames

    ' Traverse and update each sheet in the drawing
    For i = 0 To UBound(vSheetName)
        swDraw.ActivateSheet vSheetName(i)
        Set swSheet = swDraw.GetCurrentSheet
        
        ' Retrieve sheet properties and format template
        vTemplateName = swSheet.GetTemplateName
        vSheetProps = swSheet.GetProperties
        
        ' Remove the current sheet format
        swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateNone, _
                            vSheetProps(2), vSheetProps(3), False, "", _
                            vSheetProps(5), vSheetProps(6), "Default", True
                            
        ' Reload the original sheet format
        swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateCustom, _
                            vSheetProps(2), vSheetProps(3), False, vTemplateName, _
                            vSheetProps(5), vSheetProps(6), "Default", True
                            
        swDraw.ViewZoomtofit2
    Next i

    ' Activate the first sheet and force rebuild
    swDraw.ActivateSheet vSheetName(0)
    swDraw.ForceRebuild3 False
    
    ' Save the drawing
    swDraw.Save3 1, nErrors, nWarnings

    ' Clean up
    Set swDraw = Nothing
    Set swModel = Nothing
    Set swApp = Nothing

    MsgBox "Sheet format reloaded!"

End Sub

Macro

You can download the macro from here.

Customization

Need to modify the macro to meet specific requirements or integrate it with other processes? We provide custom macro development tailored to your needs. Contact us.

Author

Amen Jlili

Amen Jlili is the founder and technical director of Blue Byte Systems Inc., a software company in Vancouver, Canada, specializing in automating SOLIDWORKS and PDM. With over a decade of experience, he has authored several courses and open-source frameworks related to the SOLIDWORKS API. His leadership ensures that Blue Byte Systems prioritizes customer satisfaction and delivers high-quality software and CAD design solutions.
0
    0
    Your Cart
    Your cart is emptyReturn to Shop