Skip to content

macro for saving a individual drawing .slddrw from multiple drawing sheets in solidworks drawing #489

@chakryrp-ui

Description

@chakryrp-ui

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim sheetNames As Variant
Dim i As Integer
Dim fileBase As String
Dim outFile As String

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
    MsgBox "No document open!"
    Exit Sub
End If

If swModel.GetType <> swDocDRAWING Then
    MsgBox "Open a drawing file first!"
    Exit Sub
End If

Set swDraw = swModel

sheetNames = swDraw.GetSheetNames
fileBase = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, ".") - 1)

For i = 0 To UBound(sheetNames)
    swDraw.ActivateSheet sheetNames(i)

    outFile = fileBase & "_" & sheetNames(i) & ".slddrw"

    swModel.Extension.SaveAs outFile, _
                             swSaveAsVersion_e.swSaveAsCurrentVersion, _
                             swSaveAsOptions_e.swSaveAsOptions_Silent, _
                             Nothing, 0, 0
Next i

MsgBox "All sheets exported as individual drawing files!"

End Sub

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions