Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PDF Export Ilogic 2021 vs 2018

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
adminVC7NR
991 Views, 2 Replies

PDF Export Ilogic 2021 vs 2018

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-------


 

 

 

Labels (1)
2 REPLIES 2
Message 2 of 3
A.Acheson
in reply to: adminVC7NR

Test on INV2020

  • This line needed to be changed, if it is commented out the default is all sheets. Changed kPrintAllSheets to kPrintSheetRange.
    >oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange 

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.

 

  • This line wasn't going to stop the export but if the options aren't available it may bring back errors. Changed oDataMedium to oDocument
    >If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 

 

 

'------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-------

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3
adminVC7NR
in reply to: adminVC7NR

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.

Post to forums  

Autodesk Design & Make Report