6 Replies Latest reply on Oct 30, 2013 12:46 PM by Don Cheke

    PDF Does Not Open Automatically After Creation

    Don Cheke

      Hi All,

       

      I have been using the macro below to create PDF and DXF copies of drawings since SW2011 and sometime during SW2013 it stopped having the PDF open automatically after creation. Now with SW 2014 is still does not open automatically. Can anyone see any setting in the macro that would need adjusting or can you offer a suggested fix. I do have my PDF filter options set to open automatically after creation when I save a PDF through the save as functions.

       

      The script as seen in the editor:

       

      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 "Save as PDF DXF successful" & vbNewLine & filename

          Else

              MsgBox "Save as PDF failed, 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