- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Batch PDF multiple IDWs with Ilogic Size Issue
I have two Ilogic codes I use. One for exporting the open IDW as a PDF and one for Batch Exporting all in a selected folder to PDFs.
Single Export code actually calls for the sizing of the print
Batch Export code is calling for something other than printing, and I cant figure out where to incorporate print settings.
My workspace in Inventor is 34"x22" for modeling purposes, but our printers for real paper are 11"x17" and when printing a PDF sized 34"x22" to a real printer paper size 11"x17" it has 4" margins and is visually cluttered on the paper.
I am trying to figure out a way to make the Batch Export to include either scaling 50% or forcing the paper size to 11x17 so the resulting PDFs are all 11x17, just like as if I had done the single export.
This is the first string, that functions PERFECTLY, but only does the open IDW.
'Save IDW as PDF
If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
MsgBox("This Rule must be Run from a Drawing File", 64,"iLogic Message")
Exit Sub
End If
Dim oDrawDoc As Document
oDrawDoc = ThisApplication.ActiveDocument
Dim oPrintMgr As PrintManager
oPrintMgr = oDrawDoc.PrintManager
'specify your printer name
oPrintMgr.Printer = "CutePDF Writer"
oPrintMgr.PrintRange = kPrintAllSheets
oPrintMgr.AllColorsAsBlack = True
oPrintMgr.Orientation = kPortraitOrientation
oPrintMgr.Scale = kPrintBestFitScale
oPrintMgr.PaperSize = kPaperSizeLedger
oPrintMgr.SubmitPrint
' oDoc = ThisDoc.Document
' Dim oFileDlg As Inventor.FileDialog = Nothing
' InventorVb.Application.CreateFileDialog(oFileDlg)
' oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
' oFileDlg.FileName = iProperties.Value("Project", "Part Number")
' oFileDlg.CancelError = True
' On Error Resume Next
' oFileDlg.ShowSave()
' If Err.Number <> 0 Then
' MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
' ElseIf oFileDlg.FileName <> "" Then
' MyFile = oFileDlg.FileName & ".pdf"
' End If
' ' Get the PDF translator Add-In.
' Dim oPDFTrans As TranslatorAddIn
' oPDFTrans = ThisApplication.ApplicationAddIns.ItemById( _
' "{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
' If oPDFTrans Is Nothing Then
' MsgBox ("Could not access PDF translator.", 64, "iLogic Message")
' Exit Sub
' End If
' ' Create some objects that are used to pass information to the translator Add-In.
' Dim oContext As TranslationContext
' oContext = ThisApplication.TransientObjects.CreateTranslationContext
' Dim oOptions As NameValueMap
' oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Dim oData As DataMedium
' oData = ThisApplication.TransientObjects.CreateDataMedium
' If oPDFTrans.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
' oOptions.Value("Sheet_Range") = kPrintAllSheets
' oContext.Type = kFileBrowseIOMechanism
' oData.FileName = MyFile
' End If
' ' Call the translator.
' oPDFTrans.SaveCopyAs(ThisApplication.ActiveDocument,oContext, oOptions, oData)
And this Below is the Batch editor that prints in true size, this is the one i need to edit to include the resize but i am not sure how.
'PDF all IDW in Directory.iLogicVb: Dim oFileDlg As Inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) oFileDlg.InitialDirectory = "C:\$Workspace\Engineering Data" oFileDlg.CancelError = True oFileDlg.MultiSelectEnabled = False oFileDlg.Filter = "All Files (*.*)|*.*" oFileDlg.DialogTitle = "Choose a Directory with IDW's and/or Sub-Directories with IDW's" On Error Resume Next oFileDlg.ShowOpen() If Err.Number <> 0 Then Return ElseIf oFileDlg.FileName <> "" Then oPath = System.IO.Path.GetDirectoryName(oFileDlg.FileName) End If If MsgBox("This will write PDF files from all idw files in this location: " & vbCr & vbCr & _ oPath & vbCr & vbCr & " *** Are you sure you want to do this? ***", vbOKCancel + vbExclamation, _ "Batch Write PDF Files") = vbCancel Then Exit Sub '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 Dim MyFiles As String() ' Sets up the variable "MyFile" to be each file in the directory ' This example looks for all the files that have an .idw extension. ' This can be changed to whatever extension is needed. Also, this ' macro searches the current directory and all sub-directories. MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories) ' Starts the Loop, which will Continue Until there are no more files found. For Each MyFile As String In MyFiles ' Opens the file and saves as PDF. This can be ' changed to any procedure that would be needed to run on every ' file in the directory such as opening each file. ThisApplication.SilentOperation = True Dim partDoc As Document = ThisApplication.Documents.Open(MyFile, False) On Error Resume Next If partDoc.DocumentType = kDrawingDocumentObject Then oFileName = IO.Path.GetFileName(partDoc.FullFileName) oFileName = Left(oFileName, Len(oFileName) -4) oFileName = oFolder & "\" & oFileName & ".pdf" oPDFAddIn = partDoc.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 If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 1 'oOptions.Value("Custom_End_Sheet") = 4 End If oDataMedium.FileName = oFileName partDoc.SaveAs(oFileName, True) End If partDoc.Close(False) partDoc = Nothing ThisApplication.SilentOperation = False Next Shell("explorer.exe " & oFolder,vbNormalFocus)
Any Insite would be great, I've searched the forums and find lots of relevant posts but nothing that I can get working.
[Inventor 2020, Updated.
Intel Xeon e5-1620
26gb ram
Quadro K4000]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @TGibson7A8HD. Sorry of the delay without any responses. Sometimes when we see a lot of long code scrolling down a page, we hesitate to jump into trying to solve possible coding issues, because we assume it may take more time to diagnose than we may want to invest at the moment, plus sometimes we've just got a lot of other stuff going on.
I looked over your batch PDF export code, copied it over to a local iLogic rule editor screen for proofreading and editing. I did make some changes to it that I believe will improve its functionality, but I have not tested the result yet. Here is what I have right now that you can check out. I did not really have to move the folder selection bit out into its own Function, but that just cleans up the main part of the code a bit. I believe most folks have a similar custom function that they use in multiple scenarios, and making it modular this way makes it easier to use in many other scenarios. I often have my PDF export process out in a Sub routine of its own too, but I did not go that route with your code right now.
Sub Main
'PDF all IDW in Directory.iLogicVb:
Dim oPath As String = GetFolder
If oPath = "" Then Exit Sub
If MsgBox("This will write PDF files from all idw files in this location: " & vbCr & vbCr & _
oPath & vbCr & vbCr & " *** Are you sure you want to do this? ***", vbOKCancel + vbExclamation, _
"Batch Write PDF Files") = vbCancel Then Exit Sub
'get PDF target folder path
Dim oFolder As String = 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
Dim MyFiles As String()
' Sets up the variable "MyFile" to be each file in the directory
' This example looks for all the files that have an .idw extension.
' This can be changed to whatever extension is needed. Also, this
' macro searches the current directory and all sub-directories.
MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)
'get the PDF Translator AddIn, create variables, and set most options before loop
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 4
' Starts the Loop, which will Continue Until there are no more files found.
ThisApplication.SilentOperation = True
For Each MyFile As String In MyFiles
' Opens the file and saves as PDF. This can be
' changed to any procedure that would be needed to run on every
' file in the directory such as opening each file.
Dim drawDoc As DrawingDocument = ThisApplication.Documents.Open(MyFile, False)
If drawDoc.DocumentType <> kDrawingDocumentObject Then Continue For
Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(drawDoc.FullFileName)
oFileName = oFolder & "\" & oFileName & ".pdf"
oDataMedium.FileName = oFileName
Try
oPDFAddIn.SaveCopyAs(drawDoc, oContext, oOptions, oDataMedium)
Catch
Logger.Error("Failed to export following drawing as PDF:" & vbCrLf & drawDoc.FullFileName)
End Try
drawDoc.ReleaseReference
drawDoc = Nothing
Next
ThisApplication.SilentOperation = False
ThisApplication.Documents.CloseAll(True) 'close all unreferenced documents
Shell("explorer.exe " & oFolder, vbNormalFocus)
End Sub
Function GetFolder() As String
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = "C:\$Workspace\Engineering Data"
oFileDlg.CancelError = True
oFileDlg.MultiSelectEnabled = False
oFileDlg.Filter = "All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Choose a Directory with IDW's and/or Sub-Directories with IDW's"
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return Nothing
ElseIf oFileDlg.FileName <> "" Then
oPath = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Return oPath
End If
End Function
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I appreciate your effort and attention on this, but unfortunately it's still exporting at true size
I have a feeling what I need is simply a line in this that forces the resize, but without the knowledge of the VB language it's a bit hard to figure out.
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @TGibson7A8HD. Since the options for exporting an (.idw) drawing document to PDF do not include anything about scaling or paper size, I assume that it must look at the current 'Print Setup' and/or printing settings for things like page size, orientation, and scaling. That is likely why your other code works better, because it is specifying printer settings, then printing to a PDF printer directly. Another thing that might help would be if your drawing sheet's are designed to be the same size as the paper size you will be printing them to. When that is done, you can pretty much print at 100% or 'Actual' scale and what you have on your drawing sheet on screen will fit the paper perfectly when you print.
I assume that in this case, we just need to incorporate some DrawingPrintManager related code into the loop, just before we export the PDF, so it will know the intended paper size, orientation, and scale better before exporting. I noticed some inconsistencies between the settings of your single PDF export code and your batch PDF export codes, so I was not sure how you really wanted it set-up. In the single export, you have AllColorsAsBlack set to True, but in the PDF options, you have 'All_Color_As_Black' set to 0 (zero), which represents False. Similarly, in the single export code you are not specifying a setting for 'RemoveLineWeights', but within the batch PDF export code, you have the 'Remove_Line_Weights' setting set to 1 (which represents True). I think that is normally False, but no default is documented.
You can give this a try if you want. I just injected some of the DrawingPringManager settings into the loop as mentioned. You may want to adjust those print settings if they do not look correct to your needs.
Sub Main
'PDF all IDW in Directory.iLogicVb:
Dim oPath As String = GetFolder
If oPath = "" Then Exit Sub
If MsgBox("This will write PDF files from all idw files in this location: " & vbCr & vbCr & _
oPath & vbCr & vbCr & " *** Are you sure you want to do this? ***", vbOKCancel + vbExclamation, _
"Batch Write PDF Files") = vbCancel Then Exit Sub
'get PDF target folder path
Dim oFolder As String = 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
Dim MyFiles As String()
' Sets up the variable "MyFile" to be each file in the directory
' This example looks for all the files that have an .idw extension.
' This can be changed to whatever extension is needed. Also, this
' macro searches the current directory and all sub-directories.
MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)
'get the PDF Translator AddIn, create variables, and set most options before loop
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 4
' Starts the Loop, which will Continue Until there are no more files found.
ThisApplication.SilentOperation = True
For Each MyFile As String In MyFiles
' Opens the file and saves as PDF. This can be
' changed to any procedure that would be needed to run on every
' file in the directory such as opening each file.
Dim drawDoc As DrawingDocument = ThisApplication.Documents.Open(MyFile, False)
If drawDoc.DocumentType <> kDrawingDocumentObject Then Continue For
'set print settings
Dim oDPrintMgr As DrawingPrintManager = drawDoc.PrintManager
oDPrintMgr.AllColorsAsBlack = True
oDPrintMgr.NumberOfCopies = 1
oDPrintMgr.Orientation = PrintOrientationEnum.kPortraitOrientation
oDPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeLedger '11 x 17 inches
oDPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
oDPrintMgr.RemoveLineWeights = False
oDPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(drawDoc.FullFileName)
oFileName = oFolder & "\" & oFileName & ".pdf"
oDataMedium.FileName = oFileName
Try
oPDFAddIn.SaveCopyAs(drawDoc, oContext, oOptions, oDataMedium)
Catch
Logger.Error("Failed to export following drawing as PDF:" & vbCrLf & drawDoc.FullFileName)
End Try
drawDoc.ReleaseReference
drawDoc = Nothing
Next
ThisApplication.SilentOperation = False
ThisApplication.Documents.CloseAll(True) 'close all unreferenced documents
Shell("explorer.exe " & oFolder, vbNormalFocus)
End Sub
Function GetFolder() As String
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = "C:\$Workspace\Engineering Data"
oFileDlg.CancelError = True
oFileDlg.MultiSelectEnabled = False
oFileDlg.Filter = "All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Choose a Directory with IDW's and/or Sub-Directories with IDW's"
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return Nothing
ElseIf oFileDlg.FileName <> "" Then
oPath = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
Return oPath
End If
End Function
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@TGibson7A8HD I made an add-in for batch PDF creation several years ago. The PDF translator add-in always created a PDF in the IDW's sheet size. I ended up using the Microsoft Print to PDF driver and doing a regular print of the IDW. This should be pretty straightforward in iLogic. Just a comment on what @WCrihfield posted, the DrawingPrintManager settings do not apply to the PDF translator, only the NameValueMap Options parameter is used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I believe both strings were found online and applied rather than written by the person who sent me them.
I found this to try to use to adjust the values, https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-F3166287-12EE-4F7A-B424-AB33E4F81E53
but the other commenter mentioned that possibly the PDF export function wont call to any of these. So, I'm thinking maybe I need a different string that calls for batch printing rather than batch pdf, if that even exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @jjstr8. I agree that using a print to PDF printer routine is simpler sometimes. I use it myself in some situations. But in general, I always have my drawing sheet size set-up to match the paper size I plan on printing it to, which makes things simpler later. There are some older drawings where different sheet sizes were used and there are some odd documents here and there that use odd paper sizes too, which are good scenarios for using the print to PDF route on. In general though, probably 99% of my regular drawing PDF exports go through Inventor's PDF translator add-in at the click of a button.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the second one, they're using the PDF translator add-in. In reality, that is not actually printing. It is a document translator, much like converting an IPT to a STEP or STL file. The PDF translator does work when an IDW is opened not-visible, but has the disadvantage of not being able to set an output size. I'm on 2019, so this may have changed, but I don't think it has.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@WCrihfield I find myself doing just the opposite, sizing the sheet for the content. In the event I actually print something out, it's usually 11x17 for a catalog, or the like. If a machine shop needed an actual printed drawing, a full-size print would be of a readable size for the content...B,C,D, etc.