Attribute VB_Name = "PDF_EXPORT" Public Sub Export_All_LC_PDF() Dim oApp As Inventor.Application Set oApp = ThisApplication Dim odoc As Inventor.AssemblyDocument Set odoc = oApp.ActiveDocument Dim oBOM As Inventor.BOM Dim vrtSelectedItem As Variant vrtSelectedItem = odoc.FullFileName Set odoc = oApp.Documents.Open(vrtSelectedItem, False) Set oBOM = odoc.ComponentDefinition.BOM FirstLevelOnly = False If FirstLevelOnly Then oBOM.StructuredViewFirstLevelOnly = True Else oBOM.StructuredViewFirstLevelOnly = False End If oBOM.StructuredViewEnabled = True Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.item("Structured") printrow = 2 maxlevel = 1 Call ExportAllLCPDFChild(oBOMView.BOMRows, 1) Set BOMRow = Nothing Set oBOM = Nothing Set odoc = Nothing Set oApp = Nothing End Sub Private Sub ExportAllLCPDFChild(oBOMRows As BOMRowsEnumerator, level As Integer) 'Iterate through the contents of the BOM Rows. Dim i As Long Dim tempstr As Variant Dim tempstr1 As Variant Dim tempstr2 As Variant 'Dim oExApp As Excel.Application 'Set oExApp = GetObject(, "Excel.Application") 'Dim oExdoc As Excel.Workbooks 'Set oExdoc = oExApp.Workbooks 'Dim oExSheets As Excel.Worksheets Dim PartFileName As String Dim DWGFileName As String Dim PartTyp As String Dim PartCategory As String If level > maxlevel Then maxlevel = level End If For i = 1 To oBOMRows.Count ' Get the current row. Dim oRow As BOMRow Set oRow = oBOMRows.item(i) 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition Set oCompDef = oRow.ComponentDefinitions.item(1) 'Get the file property that contains the "Part Number" 'The file property is obtained from the virtual component definition ' Worksheets("STR_BOM").Cells(printrow, 1).Activate ' ActiveCell.Value = level PartFileName = oCompDef.Document.FullFileName PartTyp = oCompDef.Document.DocumentType '12291=Assembly , 12290= Part PartCategory = oCompDef.Document.PropertySets.item("Inventor Document Summary Information").item("Category").Value DWGFileName = (Left(PartFileName, Len(PartFileName) - 3) + "idw") 'If PartCategory = "LC" Then If FileExist(DWGFileName) = 1 Then Call PDF_EXPORT(DWGFileName) Else MsgBox "IDW does not exist for: " & PartFileName End If 'End If If TypeOf oCompDef Is VirtualComponentDefinition Then Else 'Recursively iterate child rows if present. If Not oRow.ChildRows Is Nothing Then Call ExportAllLCPDFChild(oRow.ChildRows, level + 1) End If End If Next End Sub Private Sub PDF_EXPORT(DWGFileName As String) ThisApplication.Documents.Open (DWGFileName) Dim odoc As Inventor.DrawingDocument Set odoc = ThisApplication.ActiveDocument Dim oFileName As String oFileName = odoc.FullDocumentName Dim oArray() As String oArray = Split(oFileName, "\") If odoc.FullFileName = "" Then MsgBox "Save first the Drawing..." Exit Sub End If Dim sName As String Dim i As Integer sName = oArray(LBound(oArray)) For i = 1 To UBound(oArray) - 1 sName = sName & "\" & oArray(i) Next sName = sName & "\pdf\" & (oArray(UBound(oArray))) odoc.SaveAs Replace(sName, Right(sName, 3), "PDF"), True ThisApplication.ActiveDocument.Close End Sub