AnsweredAssumed Answered

Can't SaveAs PDF in PDM Task script...

Question asked by Drew Drew on Mar 5, 2019
Latest reply on Apr 30, 2019 by Drew Drew

This script runs, the task exits, and the task manager says it executed successfully. But it doesn't save the open drawing as a pdf. It opens it, it does all the pomp and circumstance, but when it runs the Extension.SaveAs command nothing actually happens. I tried changing visibility from False to True, neither helps. Using ModelDoc2.SaveAs3 works but is antiquated and doesn't appear to be able to force silent saving (so the pdf's open after being saved). Any thoughts? Thanks!

 

Option Explicit
Sub main()
Dim swApp           As SldWorks.SldWorks
Dim swModel         As SldWorks.ModelDoc2
Dim swCustPrpMgr    As SldWorks.CustomPropertyManager
Dim longstatus      As Long
Dim longwarnings    As Long
Dim sFileName       As String
Dim Path            As String
Dim FileName        As String
Dim Value           As String
Dim DwgRev          As String
Dim Success       As Object
Dim swExtension       As SldWorks.ModelDocExtension
Dim Errors             As Long
Dim Warnings           As Long
Dim vSheetName          As Variant
Dim swExportPDFData     As SldWorks.ExportPdfData

On Error Resume Next

Set swApp = Application.SldWorks
swApp.Visible = True

sFileName = "<Filepath>"

    Set swModel = swApp.OpenDoc6(sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings)
    Set swModel = swApp.ActiveDoc
             
    swModel.ViewZoomtofit2
    
    DwgRev = swModel.GetCustomInfoValue("", "Revision")
    
    If DwgRev = "?" Or DwgRev = "" Or DwgRev = "-" Then
        DwgRev = "--"
    End If

    vSheetName = swModel.GetSheetNames
    Set swExportPDFData = swApp.GetExportFileData(1)

    FileName = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & "_" & DwgRev & ".PDF"
    'swModel.SaveAs3 "" & FileName & "", 0, 0
    swExtension = swModel.Extensiona
    Success = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, vSheetName)
    swExportPDFData.ViewPdfAfterSaving = True
    'Success = swExtension.SaveAs(FileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExportPDFData, Errors, Warnings)
    Success = swExtension.SaveAs(FileName, 0, 0, swExportPDFData, Errors, Warnings)
    swApp.QuitDoc swModel.GetTitle
    Set swModel = Nothing

End Sub

Outcomes