AnsweredAssumed Answered

Save as .slddrw .dxf and .pdf with one button click

Question asked by Will Moody on Oct 20, 2016
Latest reply on Oct 20, 2016 by Chris Mackedanz


I currently use a macro to save my drawings as dxf's and pdf's, this has caused issues if I forgot to update the dxf's and pdf's after updating my drawing (slddrw).

What would be really useful is a macro that replaced the Save button which saves as slddrw, dxf or dwg and pdf.

I have looked at my macro but cannot figure out how to change it to include a save as slddrw.


This is the macro code


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 "Saved as PDF DXF successfully" & vbNewLine & filename


        MsgBox "Save as PDF failed you did somthing wrong dumb ass, Error code:" & 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




Many Thanks