Learn how to export multiple SolidWorks drawings to PDF effortlessly using a custom macro! This step-by-step tutorial simplifies the process, saving you time and effort. Perfect for beginners and professionals looking to boost productivity in SolidWorks. Don’t forget to like, comment, and subscribe for more tutorials!
CODE:
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim exportPath As String
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Sub main()
Set swApp = Application.SldWorks
' Loop through all open documents
Dim i As Integer
Dim docCount As Integer
docCount = swApp.GetDocumentCount()
For i = 0 To docCount - 1
Set swModel = swApp.GetDocuments(i)
' Check if the document is a drawing
If swModel.GetType() = swDocDRAWING Then
Set swDraw = swModel
' Get the save path
fileName = swModel.GetPathName()
If fileName = "" Then
MsgBox "Please save the drawing file before running this macro."
Exit Sub
End If
' Set export path as the same directory as the drawing file
exportPath = Left(fileName, InStrRev(fileName, ".") - 1) & ".pdf"
' Export as PDF
swModel.Extension.SaveAs exportPath, 0, 0, Nothing, errors, warnings
If errors = 0 Then
Debug.Print "Exported: " & exportPath
Else
MsgBox "Failed to export: " & fileName
End If
End If
Next i
MsgBox "Export complete!"
End Sub