Imports System.Windows.Forms
Imports System.IO
Public Sub Main
Dim oPath As String
' Search for the folder
Dim Dialog = New FolderBrowserDialog()
Dialog.ShowNewFolderButton = True
Dialog.Description = "Jef_E Bom's export tool"
' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
' User clicked 'ok' on dialog box – capture the export path
oPath = Dialog.SelectedPath & "\"
Else
' User clicked 'cancel' on dialog box – exit
Return
End If
' Make a reference to a directory.
Dim oDirectoryInfo As New DirectoryInfo(oPath)
' Get a reference to each file in that directory.
Dim oFileArray As FileInfo() = oDirectoryInfo.GetFiles()
' Display the names of the files.
Dim oFileInfo As FileInfo
' Loop through all files in the directory (not in the sub directories.)
For Each oFileInfo In oFileArray
If oFileInfo.Name.contains(".iam") Then
' Open the file
ThisApplication.Documents.Open(oFileInfo.FullName, True)
' Export the BOM
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
' Set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
Dim oExcelPath As String
oExcelPath = oPath & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)& ".xls"
' Export the BOM view to an Excel file
oStructuredBOMView.Export(oExcelPath, kMicrosoftExcelFormat)
' Close the document
oDoc.Close
End If
Next
End Sub