I have been reading some posts on these forums regarding automatically exporting PDFs with set names. It has been going okay. I've managed to be able to export PDFs of my Inventor drawings every time I hit 'save'. But a few things aren't working.
1. The code exports the same number of PDFs as there are sheets in my drawing, EXCEPT, every PDF contains the image that is in Sheet 1. So if I have a 5 sheet drawing and export it, all 5 PDFs will depict what is contained in Sheet 1.
2. The code does not create a new folder called 'PDF' to store the PDFs in. Nor does it store the PDFs in that folder if I create it beforehand. I pretty much copied the code exactly from a tutorial I saw on how to do just that, so I'm not sure why it's not working.
Here is my iLogic code. Hopefully someone can help. Thank you. 🙂
'------start of iLogic-------oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extensionoPDFAddIn = 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 'Define the drawing Dim oDrawing As DrawingDocument oDrawing = ThisDoc.Document Dim oSheet As Sheet Dim lPos As Long Dim rPos As Long Dim sLen As Long Dim sSheetName As String Dim iSheetNumber As Integer Dim sheetCount As Integer = ThisDrawing.Document.Sheets.Count 'step through each drawing sheetFor Each oSheet In oDrawing.Sheets 'find the seperator in the sheet name:numberlPos = InStr(oSheet.Name, ":") 'find the number of characters in the sheet namesLen = Len(oSheet.Name) 'find the sheet namesSheetName = Left(oSheet.Name, lPos -1) 'find the sheet numbersSheetNumber = Right(oSheet.Name, sLen -lPos) 'set PDF OptionsIf oPDFAddIn.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.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = sSheetNumber oOptions.Value("Custom_End_Sheet") = sSheetNumber End If 'get PDF target folder pathoFolder = Left(oPath, InStrRev(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 If sheetCount=1 Then 'Set the PDF target file nameoDataMedium.FileName = oPath & "\" & oFileName & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf" End If If sheetCount>1 'Set the PDF target file nameoDataMedium.FileName = oPath & "\" & oFileName & "-0" & sSheetNumber & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf" End If 'Publish documentoPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next '------end of iLogic-------
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
Solved by rossano_praderi. Go to Solution.
Hi, this is "your" code with some corrections.
The old code may have created new folders in a different location, try to have a look in your workarea.
'------start of iLogic------- oDocument = ThisApplication.ActiveDocument oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium Dim oDrawing As DrawingDocument = ThisDoc.Document Dim oSheet As Sheet Dim lPos, rPos,sLen As Long Dim sSheetName As String Dim sSheetNumber As Integer Dim sheetCount As Integer = oDrawing.Sheets.Count oFolder = oPath & "\PDF" If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If For Each oSheet In oDrawing.Sheets lPos = InStr(oSheet.Name, ":") sLen = Len(oSheet.Name) sSheetName = Left(oSheet.Name, lPos -1) sSheetNumber = Right(oSheet.Name, sLen -lPos) If oPDFAddIn.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.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = sSheetNumber oOptions.Value("Custom_End_Sheet") = sSheetNumber End If If sheetCount = 1 Then oDataMedium.FileName = oFolder & "\" & oFileName & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf" ElseIf sheetCount > 1 oDataMedium.FileName = oFolder & "\" & oFileName & "-0" & sSheetNumber & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf" End If oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next '------end of iLogic-------
Bregs
Rossano Praderi
Hey, thanks!
Another question, if you don't mind. I have my Inventor set up to export the PDFs right before I save, every time I save, but when if I have multiple drawings open and click, "Save All", every PDF that gets exported will have the image of the sheet that was open when I clicked 'Save All'.
Any idea why?
Hi,
I would like to know if you have tried my code?
@mwnadolny wrote:Hey, thanks!
Another question, if you don't mind. I have my Inventor set up to export the PDFs right before I save, every time I save, but when if I have multiple drawings open and click, "Save All", every PDF that gets exported will have the image of the sheet that was open when I clicked 'Save All'.
Any idea why?
This could be the solution to yours last question.
In this way the running Ilogic code will be correctly associated with its "Document".
By using yours code on the "ActiveDocument" this will be executed only on this one, you know what i mean.
'Substitute this declaration oDocument = ThisApplication.ActiveDocument 'With this Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(ThisDoc.PathAndFileName(True))
Bregs
Rossano Praderi
You are welcome.
I would be happy if you accept my solution.
Thank you.
Bregs
Rossano Praderi