Problem with exporting BOM to excel using Inventor 2017

Problem with exporting BOM to excel using Inventor 2017

Anonymous
Not applicable
942 Views
2 Replies
Message 1 of 3

Problem with exporting BOM to excel using Inventor 2017

Anonymous
Not applicable

Hi , i am trying to export a BOM from Inventor 2017 using this code, but i get 3 errors. 

 

1) I can't disable the FirstlevelOnly option  i get  "Invalid procedure call or argument", so i am forced to make this line a comment.

2) The same thing happens with the selection of the Structured type of View. so i change the code with "Set oStructuredBOMView = oBOM.BOMViews.Item(1).

3)  With the corrections mentioned above , the last line gives me an error of type " Object doesn´t support this action"

 

Please help me correct the error or find a new solution .

 

Thank you

 

Public Sub BOMAllLevelExport()
' 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 ThisApplication.FileLocations.Workspace & "\BOM.xls", kMicrosoftExcelFormat

End Sub

0 Likes
Accepted solutions (1)
943 Views
2 Replies
Replies (2)
Message 2 of 3

Jon.Balgley
Alumni
Alumni
Accepted solution

Works for me!

 

I made a simple assembly ... two occurrences of AAA, each having 1 occurrence each of ppp and qqq.  And a first-level part, bar.

 

Running your code as is, gave me this, showing the second level of the structure.

 

BOM Structure Description Item Part Number REV Stock Number Thumbnail QTY Unit QTY
Normal   1 aaa     (NULL) 2 1
Normal   1.1 ppp     (NULL) 1 1
Normal   1.2 qqq     (NULL) 1 1
Normal   2 bar     (NULL) 1 1

 

 

Then I changed this line to use "true":

    oBOM.StructuredViewFirstLevelOnly = True

 

And I got this, showing only the first level of the structure:

 

BOM Structure Description Item Part Number REV Stock Number Thumbnail QTY Unit QTY
Normal   1 aaa     (NonDisplayable) 2 1
Normal   2 bar     (NonDisplayable) 1 1

 

Give it a try again, and let me know what happens.


Jon Balgley
Message 3 of 3

Anonymous
Not applicable

Yes you are right , i made a new assembly just like you and it worked. It was the assembly that i was using , i realized it was the level of detail , because i needed to surpress some parts on the assembly.

 

Thank you very much for your help 

0 Likes