Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I found this script in another thread (https://forums.autodesk.com/t5/inventor-forum/ilogic-rule-quot-auto-export-pdf-on-save-quot/td-p/538...) to export/save a pdf from a drawing upon save. This works really good but I would like to add a error message if the file was unable to be saved/updated, most likely cause the PDF is open or in use somewhere. As of now the error that shows up is "(Exception from HRESULT: 0x80004005 (E_FAIL))" I would like to simply add a MessageBox instead. Happy if anyone could help me out.
Here's the script:
' Get the PDF translator Add-In. Dim PDFAddIn As TranslatorAddIn PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then 'oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If PDFDirectory = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension If ThisDoc.Path = "" Then MessageBox.Show("PDF file not created, click Save button again for PDF creation.", "iLogic") Return 'exit rule Else oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF" End If 'Publish document. PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Launch the PDF file in whatever application Windows is set to open this document type with 'i = MessageBox.Show("Preview the PDF file?", "PDF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName) On Error MessageBox.Show("PDF not saved, file is in use. Please close the PDF-document and try again", "iLogic")
Thanks
/Fredrik
Solved! Go to Solution.