EXPORT BOM

EXPORT BOM

Anonymous
Not applicable
1,858 Views
8 Replies
Message 1 of 9

EXPORT BOM

Anonymous
Not applicable

hi friends,

 

i have 400 assemblies in a folder and i would like to export bom of all assemblies.

I there any short way (Ex: task scheduler procedure) to export all the boms in single oprations.

Please suggest.

0 Likes
Accepted solutions (1)
1,859 Views
8 Replies
Replies (8)
Message 2 of 9

Jef_E
Collaborator
Collaborator

Yes, it's possible. Do you want it exported to 400 different Excel files?

Please give more information when asking "is it possible".

 

It's the golden age of computers, almost anything is possible. If you know how!

 

You could create a loop for each document in the folder folder?

 

For each file in folder

     Open file
     Export BOM
     Close file

Next


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 9

Anonymous
Not applicable

 

yes i want to export into individual files. 

file name can be same as assembly file name.

i dont want to open each file and waste my time in doing same work for every file (Conventional process). 

 

0 Likes
Message 4 of 9

Jef_E
Collaborator
Collaborator

And you want me to write this code for you? Or you need help writing it?

 

 

Code sample (copy paste from the programming help)

Public Sub BOMExport()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' Set a reference to the BOM
    Dim oBOM As BOM
    Set 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
    Set oStructuredBOMView = oBOM.BOMViews.Item("Structured")
    
    ' Export the BOM view to an Excel file
    oStructuredBOMView.Export "C:\temp\BOM-StructuredAllLevels.xls", kMicrosoftExcelFormat
  
    ' Make sure that the parts only view is enabled.
    oBOM.PartsOnlyViewEnabled = True

    ' Set a reference to the "Parts Only" BOMView
    Dim oPartsOnlyBOMView As BOMView
    Set oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")

    ' Export the BOM view to an Excel file
    oPartsOnlyBOMView.Export "C:\temp\BOM-PartsOnly.xls", kMicrosoftExcelFormat
End Sub


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 5 of 9

Anonymous
Not applicable
Dear jef_E,

Thanks for your response.
i have found the same code much earlier. But the problem is i need to do this program for all 400 assemblies. (I.e i need to write/paste ilogic rule in 400 assemblies) Instead of doing this it is much better to proceed in conventional way(Open file,Export BOM,Close file).
I am expecting a solution like task scheduler where i can give the path of assemblies folder and i will get all the excel files of BOMs.

I feel its better for me to proceed in conventional method instead of holding my work.

Thanks again for the response,
0 Likes
Message 6 of 9

Jef_E
Collaborator
Collaborator

One last question before I can give you the code you need. (run-able from i-Logic)

 

The 400 assemblies are all in the same folder? Or are they also located in sub-folders?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 7 of 9

Anonymous
Not applicable
There is no sub folders. in one folder all assembly files are located.
0 Likes
Message 8 of 9

Jef_E
Collaborator
Collaborator
Accepted solution

Here, is the code. Just run an new Inventor application, open a empty part, add a iLogic rule, paste the code and GO.

It will ask to point to the folder. So you shouldn't make any edits to the code.

The excel files with the exported are saved in the same folder with the same name as the assembly.

 

I didn't add a progress bar.. you can monitor the progress by watching the folder.

 

If the assembly has unresolved documents, it will not export a BOM to excel. Just so you know..

 

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

Please kudo my posts and accept as solution.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 9 of 9

victor.gilgarcia
Explorer
Explorer

Hi,

 

I am trying to do the same thing but I have each assembly in a separate subfolder.

 

So I want to create the iLogic program so it exports to xls the Bom of each assembly of each subfolder within one folder. How should I update the code?

 

 

Thanks!

0 Likes