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. (Note This code has been edited and improved since recording the video).

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")
 UserSelectedActionList = New String(){"DXF & PDF", "PDF Only", "DXF Only"}
  UserSelectedAction = InputListBox("What action must be performed with selected views?", _
          UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
      Select UserSelectedAction
   Case "DXF & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DXF Only":    UserSelectedAction = 2
   End Select
 If userChoice Then
   Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, UserSelectedAction)
  Else
   For Each oDoc In ThisApplication.Documents
    If oDoc.DocumentType = kDrawingDocumentObject
     Try
      If Len(oDoc.File.FullFileName)>0 Then
       Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
      End If
     Catch
     End Try
    End If
   Next
  End If
 End Sub
 Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer)
 ' oPath = oDocument.Path
 ' oFileName = oDocument.FileName(False) 'without extension
  'oDocument = ThisApplication.ActiveDocument
  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
 oFullFileName = oDocument.File.FullFileName
  oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
  oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
  oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)
 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number")
  'oDocument = ThisApplication.ActiveDocument
 ' If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
  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
  'oOptions.Value("Custom_Begin_Sheet") = 2
  'oOptions.Value("Custom_End_Sheet") = 4
 ' End If
 'get PDF target folder path
  'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"
  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
   System.IO.Directory.CreateDirectory(oFolder)
  End If
 'Set the PDF target file name
  oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf"
 'Publish document
  If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then
   oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's
  End If
  If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then
   oDocument.SaveAs(oFolder & "\" & oFilePart & ".dxf", True) 'For DXF's
  End If
  'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".dxf"), True) 'For DXF's
  '------end of iLogic-------
 End Sub

Advertisements

20 comments

  • Hey man! I’m from Brazil and just need to thank so much.

  • Good morning ,
    This rule is amazing, is saving me a considerably amount of time.
    Is there any way to modify the code to save only the profile of the part without the whole title block and dimensions?

    Really appreciate your efforts in providing this great code,

    Thanks,

    Eric

  • David Stanhope

    Hi there, terrific piece of code, very helpful, well done
    Thanks
    Dave

  • Walter Leenes

    Hello, love this Rule.
    However, I’m trying to get the oRevNum to work and have it add this to my filename.

    Removing the comment mark of your line for oRevNum, stops the Rule from working (no error message, but it just won’t execute beyond the inputboxes.

    If I remove the “oDocument” part in front of iProperties, I only get the revision number of the active document on all other saved documents. Hope you can help me here. Many thanks, Walter

  • I do not know who you are but you literally saved my life. Thank you very much.

  • Luke Adam Nash

    Legendary, thanks for this. I modified it slightly so that it requires me to enter a revision number and only does pdf.

    If this helps anyone else, here’s the ilogic code:

    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”)
    Revision = InputBox(“Enter Revision”, “Revision Selection”, “0”)
    If userChoice Then
    Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, Revision)
    Else
    For Each oDoc In ThisApplication.Documents
    If oDoc.DocumentType = kDrawingDocumentObject
    Try
    If Len(oDoc.File.FullFileName)>0 Then
    Call MakePDFFromDoc(oDoc, myDate, Revision)
    End If
    Catch
    End Try
    End If
    Next
    End If
    End Sub
    Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, Revision As String)

    ‘ oPath = oDocument.Path
    ‘ oFileName = oDocument.FileName(False) ‘without extension
    ‘oDocument = ThisApplication.ActiveDocument
    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
    oFullFileName = oDocument.File.FullFileName
    oPath = Left(oFullFileName, InStrRev(oFullFileName, “\”)-1)
    oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, “\”))
    oFilePart = Left(oFileName, InStrRev(oFileName, “.”)-1)
    ‘oRevNum = oDocument.iProperties.Value(“Project”, “Revision Number”)
    ‘oDocument = ThisApplication.ActiveDocument
    ‘ 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.kPrintAllSheets
    ‘oOptions.Value(“Custom_Begin_Sheet”) = 2
    ‘oOptions.Value(“Custom_End_Sheet”) = 4
    ‘ End If
    ‘get PDF target folder path
    ‘oFolder = Left(oPath) & “PDF”
    oFolder = oPath
    ‘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
    ‘Set the PDF target file name
    oDataMedium.FileName = oFolder & “\” & oFilePart & “-REV” & Revision & “.pdf”
    ‘Publish document
    oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)’For PDF’s
    ‘oDocument.SaveAs(oFolder & “\” & ThisDoc.ChangeExtension(“.dxf”), True) ‘For DXF’s
    ‘——end of iLogic——-
    End Sub

    • Rodney Peterson

      Nice, we use DWG files for our Inventor drawings, I do not know anything about I-logic, can this code be change to save pdf of open DWG files? Also, I dont need the revision portion either.

      tuy

    • Ey Luke
      Awesome rule. Thanks

      Can you tell me , how I save as : Inventor dwg(one file and multiplessheets)? diferent that autocad dwg(multiples files)

      Thanks for your help

  • Hi all,

    This is great, but would anyone be able to adjust it so it separates out the drawing sheets within a single IDW to separate PDF files, instead of one combined PDF?

  • Very usefull i-logic, Thanks!

  • Terrific code!

    This is time saving. I´ve been trying to get the Tiltle from the part model to use as a name for the pdf file but I have not succed it, so I have to change it manually. Do you have any ideas how to do that? I tried to modify the code but it just get the Tiltle of the last drawing.

    Thank you again!

  • I tried to alter the rule to create a loop and export all sheets from a drawings file (multi sheet dwg) as an individual pdfs. Unfortunately I could not make it to work. Has anyone done such code?

  • Awesome!

    Can someone modify that sheet 1 will be the PDF only, while sheet 2 will be the dxf only..

    Thanks!

  • Hola quisiera encontrar alguna solucion para recuperar uns pdf que fueron creados desde autocad vovrelos a pasar a dwg. me ayudaria? estoy usando vb .net

  • Thank You!!!! You saved me soooooo much time. I would have spent days exporting PDF’s and given myself carpel tunnel. Thank you Thank you!!! And the PDF only option was a perfect addition.

  • Truly a God send. What amazed me was how it automatically selected the correct paper size, letter vs tabloid. Great effort on your part. Thank you.

  • Thank you so much. This code save me a lot of time!
    For the company I am working, we are required to add revision suffix “_r0” for each pdfs while archiving. I’ve tried to modify part the code for the naming section, then revision suffix can be added while run the code.
    But I’ve also met a problem, it will only reflect revision in the activate drawing to all the PDFs. Could you please help to take a look at that how to modify the code for?

    oDataMedium.FileName = oFolder & “\” & oFilePart & “.pdf”
    oDataMedium.FileName = oFolder & “\” & oFilePart & “_r” & iProperties.Value(“Project”, “Revision Number”) & “.pdf”

    • Hi Lei

      Try these lines instead:

      docRev = oDocument.PropertySets(“Summary Information”).Item(“Revision Number”).value
      oDataMedium.FileName = oFolder & “\” & oFilePart & “_r” & docRev & “.pdf”

      That should do the trick

  • How I could export the pdf or dwg to a desinated folder?

Leave a Reply

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