pdf & dxf export adding sheet name to filename for multi-sheet
Posted: Tue Jul 02, 2024 12:29 pm
Hello,
For years I've been using a macro to export a SW drawing file as in pdf and dxf format in one go.
I use it daily and it's saved me so much time over the years.
I'd love to add an extra level of function to it, whereby any multi-sheet drawings are exported as individual dxf files with the sheet name as a suffix of each file name rather than the default numerical prefix.
I've tried editing the macro to add this, but my knowledge is negligible and have got nowhere.
I'll paste the existing code below, and if anyone can help me achieve what I'm after I'll be extremely grateful.
Thanks,
Martin
'------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sPathName As String
Dim nErrors As Long
Dim nWarnings As Long
Dim nRetval As Long
Dim bShowMap As Boolean
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swExportData As SldWorks.ExportPdfData
Dim filename As String
Dim boolstatus As Boolean
Dim lErrors As Long
Dim lWarnings As Long
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Strip off SolidWorks drawing file extension (.slddrw)
' and add DXF file extension (.dxf)
sPathName = swModel.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 6)
sPathName = sPathName + "dxf"
' Show current settings
' Turn off showing of map
bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)
Set swModelDocExt = swModel.Extension
Set swExportData = swApp.GetExportFileData(swExportPDFData)
filename = swModel.GetPathName
filename = Strings.Left(filename, Len(filename) - 6) & "PDF"
boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)
boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportData, lErrors, lWarnings)
If boolstatus Then
MsgBox "A .PDF and a .DXF have been saved." & vbNewLine
Else
MsgBox "I didn't like that!" & lErrors '
End If
swApp.SetUserPreferenceToggle swDXFDontShowMap, False
bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
If bRet = False Then
nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)
End If
' Restore old setting
swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap
End Sub
'----------------------------------------------
For years I've been using a macro to export a SW drawing file as in pdf and dxf format in one go.
I use it daily and it's saved me so much time over the years.
I'd love to add an extra level of function to it, whereby any multi-sheet drawings are exported as individual dxf files with the sheet name as a suffix of each file name rather than the default numerical prefix.
I've tried editing the macro to add this, but my knowledge is negligible and have got nowhere.
I'll paste the existing code below, and if anyone can help me achieve what I'm after I'll be extremely grateful.
Thanks,
Martin
'------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sPathName As String
Dim nErrors As Long
Dim nWarnings As Long
Dim nRetval As Long
Dim bShowMap As Boolean
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swExportData As SldWorks.ExportPdfData
Dim filename As String
Dim boolstatus As Boolean
Dim lErrors As Long
Dim lWarnings As Long
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Strip off SolidWorks drawing file extension (.slddrw)
' and add DXF file extension (.dxf)
sPathName = swModel.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 6)
sPathName = sPathName + "dxf"
' Show current settings
' Turn off showing of map
bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)
Set swModelDocExt = swModel.Extension
Set swExportData = swApp.GetExportFileData(swExportPDFData)
filename = swModel.GetPathName
filename = Strings.Left(filename, Len(filename) - 6) & "PDF"
boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)
boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportData, lErrors, lWarnings)
If boolstatus Then
MsgBox "A .PDF and a .DXF have been saved." & vbNewLine
Else
MsgBox "I didn't like that!" & lErrors '
End If
swApp.SetUserPreferenceToggle swDXFDontShowMap, False
bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
If bRet = False Then
nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)
End If
' Restore old setting
swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap
End Sub
'----------------------------------------------