Hello,
The below code I had pieced together had worked flawlessly for some time with Inventor 2018.
It usually exports only the first page of a multi sheet document.
However with 2021, it exports the all sheets as a single pdf, which is not the original intent.
Can you please review & comment as to why the version change would affect the code?
'------start of iLogic-------
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'2018 PDF EXPORT
'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
'oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
'oOptions.Value("Sheet_Range") = 'Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = 1
oOptions.Value("Custom_End_Sheet") = 1
'End If
'get PDF target folder path
oFolder = oPath & "\PDF"
'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev" & oRevNum & " GA" & ".pdf"
On Error Goto handlePDFLock
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'--------------------------------------------------------------------------------------------------------------------
Exit Sub
handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next
'Show message box
MessageBox.Show("Drawing saved and PDF Exported to LAST EDITED document folder/PDF", "Save I-logic")
'------end of iLogic-------
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Test on INV2020
kPrintSheetRange was found in the rule editor but is also in the API Help under PrintRangeEnum Enumerator.
This wasn't shown in the Export to PDF Sample, so not immediately clear it had to be used. Perhaps there was a change at a certain release, as other samples on the forum didn't use this either.
'------start of iLogic------- oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension oRevNum = iProperties.Value("Project", "Revision Number") oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oDocument = ThisApplication.ActiveDocument oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium '2018 PDF EXPORT If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 'Changed oDataMedium to oDocument 'oOptions.Value("All_Color_AS_Black") = 0 'oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'Sheet Range oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 End If 'get PDF target folder path oFolder = oPath & "\PDF" 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & _ " Rev" & oRevNum & " GA" & ".pdf" On Error GoTo handlePDFLock 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) '-------------------------------------------------------------------------------------------------------------------- Exit Sub handlePDFLock: MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!") Resume Next 'Show message box MessageBox.Show("Drawing saved and PDF Exported to LAST EDITED document folder/PDF", "Save I-logic") '------end of iLogic-------
Thankyou,
Good pickup on the kPrintAllSheets to kPrintSheetRange. Can confirm if works this end.
I did quickly try your export custom number of pdf link, however it threw an error also.
Maybe for another day.
Can't find what you're looking for? Ask the community or share your knowledge.