Trying to make a small modification to the Office to PDF script.
The output file path passes to the script the following default path definition (ignore FileSate, it's not relevant here):
\ - REV <%Revision%> - <%FileState%>
For legibility, I want "REV -" to read "REV NEW". I modified the code in the ConvertWordDocToPDF() function in the otherwise unchanged Office to PDF script, as shown at the bottom of this post. The modification resolves the output file path into a string variable, and a replace operation then changes any instance of "REV -" in that variable to "REV NEW". Very simple.
The replace operation results in the desired filename (as written to the log file). With the replace operation commented out, the code below works fine and exports to the original filename. So that much works.
But with the the replace operation active, it fails every time, with the following log message:
[16.04.2020 16:33:10.680]Initial value of OutputPath: C:\Users\tljames\AppData\Roaming\SWPDFTaskAddIn\PD10003 - REV - - DRAFT.pdf
[16.04.2020 16:33:10.681]Save document as pdf: C:\Users\tljames\AppData\Roaming\SWPDFTaskAddIn\PD10003 - REV NEW - DRAFT.pdf
[16.04.2020 16:33:13.583] Error: The supplied object ID is not valid.
The error message appears to be connected with the line "Return success" just before the end of the function.
What am I missing here?
----- Modified code below:
SolidworksSolidworks Pdm/enterprise Pdm'Word bookmarks takes precedence
'1 - WdExportCreateBookmarks.wdExportCreateHeadingBookmarks
'2 - WdExportCreateBookmarks.wdExportCreateWordBookmarks
Dim paramCreateBookmarks As Int32 = If(doc.Bookmarks.Count < 1, 1, 2)' (int)Word.WdSaveFormat.wdFormatPDF = 17
'Log("Save document as pdf" + "[OutputPath]")' -----------------------------------MODIFIED CODE-------------------
Dim expPath as String
expPath = "[OutputPath]"
Log("Initial value of OutputPath: " + "[OutputPath]")
expPath = Cstr(Replace(expPath, "REV -", "REV NEW"))
Log("Save document as pdf: " + expPath )
doc.ExportAsFixedFormat(expPath, _
paramExportFormat, paramOpenAfterExport, _
paramExportOptimizeFor, paramExportRange, paramStartPage, _
paramEndPage, paramExportItem, paramIncludeDocProps, _
paramKeepIRM, paramCreateBookmarks, _
paramDocStructureTags, paramBitmapMissingFonts, _
paramUseISO19005_1)' -------------------------------------------------------------------------
If Not String.IsNullOrEmpty("[Sec_OutputPath]") Then
'Log("Save document second output file as pdf" + "[Sec_OutputPath]")