AutoDesk Inventor – Batch Exporting PDFs & DXFs with iLogic

If you have ever had to publish a lot of Inventor IDW drawings at the same time, you will know how tedious it can be to go into each drawing and Save Copy As each file as a DXF or PDF individually.

Here is where iLogic can come to the rescue. I have written an iLogic rule that will automatically export all IDW drawings that are open in your Inventor session in a timestamped folder. Each time the rule is run it will create a new timestamped folder so that you will easily be able to find your newest exported files. The video below gives a demonstration of how it works.

To use this rule yourself, open the iLogic browser in an Inventor session. Create a new rule called Export PDF’s & DXF’s, and paste the following code into the rule before saving and running the rule.

Sub Main()
 Dim myDate As String = Now().ToString("yyyy-MM-dd HHmmss")
 myDate = myDate.Replace(":","")  ' & " - " & TypeString
 userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 If userChoice Then
  Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate)
  For Each oDoc In ThisApplication.Documents
   If oDoc.DocumentType = kDrawingDocumentObject
     If Len(oDoc.File.FullFileName)>0 Then
      Call MakePDFFromDoc(oDoc, myDate)
     End If
    End Try
   End If
 End If

End Sub

Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String)
 oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
 oContext = ThisApplication.TransientObjects.CreateTranslationContext
 oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
 oOptions = ThisApplication.TransientObjects.CreateNameValueMap
 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

 oFullFileName = oDocument.File.FullFileName
 oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
 oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
 oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)

 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
 'get PDF target folder path
 oFolder = oPath & "/iLogic PDF's (" & DateString & ")"
 'Check for the PDF folder and create it if it does not exist
 If Not System.IO.Directory.Exists(oFolder) Then
 End If
 'Set the PDF target file name
 oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf"
 'Publish document
 oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's
 oDocument.SaveAs(oFolder & "\" & oFilePart & ".dxf", True) 'For DXF's
 '------end of iLogic-------
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *