Greetings. I'm very new to iLogic, however I've been guided through the process of creating a rule which auto-exports a PDF of an IDW upon saving the IDW.
It works great... the only problem is that it won't export the PDF on the intial save of the IDW. You need to do the initial save, then upon the second save of the IDW, the PDF will be exported. Major first-world problem 🙂
Anybody know how to get the PDF to export upon initial save? Below is the code that I've used (thanks for any help you can provide; BTW we're running Inventor Professional 2015):
' 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
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
'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)
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi ccamara01,
I've not really ever found an elegant solution for this (it could be that I just didn't look hard enough), but this is what I use to get past the error that occurs when the file has yet to be saved and therefore has no path. When it detects this, I simply click OK in the message and then click the Save button again.
If ThisDoc.Path = "" Then MessageBox.Show("PDF file not created, click the Save button again.", "iLogic") Return 'exit rule Else oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF" End if
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks for the response Curtis. This approach at least gives you a visual indicator that the PDF hasn't been created yet. Obviously not the solution I was hoping for, but better than the alternative.
I've placed your coding just before my final command line... is this the right place for it? See in red below...
' 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
oDataMedium.FileName = PDFDirectory & "\" & oFileName & ".PDF"
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)
Thanks,
Curtis
The code first posted worked just fine for me.. The PDF was created on the initial save.
Hi ccamara01,
I think what you had would work, but you had the oDataMedium line in there twice:
' 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)
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Believe it or not... if the initial save of the IDW is done using "Save" (Windows 7), it will export the PDF. If the initial save is done using "Save As", it won't export the PDF until the second save. Just realized this...
Having created pdf files and opened as well, now I have a bunch of pdf files open. Inventor drawings closes in the drawing creation rule.
I tries several including the following.
Try ' Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) ' Ask the user if he wants to open the file Open_PDF = MessageBox.Show("Open PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Open_PDF = vbYes Then ThisDoc.Launch(oDataMedium.FileName) End If Catch MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!") End Try Close_PDF = MessageBox.Show("Close the PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Close_PDF = vbYes Then ThisDoc.Close(oDataMedium.FileName) Else 'do nothing End If
Above part for Close_PDF doesn't run.
I would like to receiving help.
Having created pdf files and opened as well, now I have a bunch of pdf files open. Inventor drawings closes in the drawing creation rule.
I tries several including the following.
Try ' Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) ' Ask the user if he wants to open the file Open_PDF = MessageBox.Show("Open PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Open_PDF = vbYes Then ThisDoc.Launch(oDataMedium.FileName) End If Catch MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!") End Try Close_PDF = MessageBox.Show("Close the PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If Close_PDF = vbYes Then ThisDoc.Close(oDataMedium.FileName) Else 'do nothing End If
Above part for Close_PDF doesn't run.
I would like to receiving help.
Google-Fu is a great resource.
looks like you probably have to grab the process and terminate it.
Something like this...
<vb.net>
Add System.Diagnostic namespace Then Dim myProcesses() as Process 'single process variable Dim myProcess As Process 'Get the list of processes myProcesses = Process.GetProcesses() For Each myProcess in myProcesses if myProcess.ProcessName = "Acrobat.exe" Then myProcess.Terminate() if myProcess.ProcessName = "AcroRd32.exe" Then myProcess.Terminate() Next