Met deze iLogic regel kan je alle drawings van een assembly en alle drawings van de assembly componenten in 1 keer exporteren naar pdf.


De regel zoekt naar bestaande .idw of .dwg bestanden op dezelfde locatie waar de assembly of part files opgeslagen zijn. De pdf bestanden worden ook op die locatie opgeslagen. Als er geen .idw of .dwg gevonden wordt, dan wordt dat component overgeslagen.

De code hieronder werkt voor .idw bestanden. Als je binnen uw organisatie .dwg bestanden gebruikt dan kan je regel 31 wijzigen naar het volgende:


Dim idwPathName = IO.Path.ChangeExtension(refDoc.FullDocumentName, ".dwg")

Hier is de volledige code:


'This iLogic Rule starts from an assembly and saves all associated .idw files of the assembly and the individual components to PDF.
Sub Main()

  If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
  End If

  Dim RUsure = MessageBox.Show("This will create a PDF file for all of the asembly components that are sheet metal." _
    & vbLf & "This rule expects that the part file is saved." _
    & vbLf & " " _
    & vbLf & "Are you sure you want to create PDF for all of the assembly components?" _
    & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ", MessageBoxButtons.YesNo)

  If RUsure = DialogResult.No Then Return

  Dim oAsmDoc As AssemblyDocument = ThisDoc.Document

  For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
    export(oRefDoc, ThisDoc.Path)
  Next

  export(oAsmDoc, ThisDoc.Path)

  MessageBox.Show("PDF FILES ARE READY")

End Sub

Sub export(refDoc As Document, exPath As String)

  Dim idwPathName = IO.Path.ChangeExtension(refDoc.FullDocumentName, ".idw")

  ' Check to see that the model has a drawing of the same path and name
  If (System.IO.File.Exists(idwPathName)) Then

    Dim pdfAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    Dim drawDoc As DrawingDocument = ThisApplication.Documents.Open(idwPathName, True)


    'blader door sheets en exporteer
    For Each sheet As Sheet In drawDoc.Sheets

      Dim sheetName As String = Split(Sheet.Name, ":")(0)
      Dim sheetNumber As Integer = Split(Sheet.Name, ":")(1)

      Dim context = ThisApplication.TransientObjects.CreateTranslationContext()
      context.Type = IOMechanismEnum.kFileBrowseIOMechanism

      Dim oDataMedium = ThisApplication.TransientObjects.CreateDataMedium()

      'set PDF Options
      Dim options = ThisApplication.TransientObjects.CreateNameValueMap
      options.Value("All_Color_AS_Black") = 1
      options.Value("Remove_Line_Weights") = 1
      options.Value("Vector_Resolution") = 400
      options.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
      options.Value("Custom_Begin_Sheet") = sheetNumber
      options.Value("Custom_End_Sheet") = sheetNumber

      Dim fileName As String = drawDoc.DisplayName
      Dim revNum = drawDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
      ' use this if you want the revision number of the part/assembly file
      ' Dim revNum = refDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value

      oDataMedium.FileName = exPath & "\" & fileName & " " & "Rev" & revNum & ".pdf"

      'Publish document
      pdfAddIn.SaveCopyAs(drawDoc, context, options, oDataMedium)

    Next

    drawDoc.Close(True)
  End If
End Sub

Veel plezier!


Klik hier om te zien hoe je iLogic rules kan inladen en gebruiken in Inventor.

Controleer onze opleidingskalender voor meer informatie over Inventor.