@sstembridgeCNX3B But just incase you already know how to do it manually, but still want to do it by code, there are a couple ways to do it. There is an iLogic shortcut snippet that could be used, then there is the normal Inventor API way. The iLogic shortcut snippet route requires less overall code, but gives you less control and fewer options. For example, it does not make sure we are working with an assembly, so may throw an error if it is not an assembly. It may not ensure that the structured view has been enabled or that the 'all levels' setting has been set to True yet.
Dim sFileName As String = ThisDoc.PathAndFileName(False) & ".xlsx"
ThisBOM.Export("Structured", sFileName, FileFormatEnum.kMicrosoftExcelFormat, "Assembly BOM - Structured All Levels")
And below is the regular Inventor API way, which includes the extra precautions and options.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then
Logger.Debug("iLogic rule '" & iLogicVb.RuleName & "' was aborted - no AssemblyDocument found.")
Return
End If
If oADoc.RequiresUpdate Then oADoc.Update2(True)
Dim oBOM As Inventor.BOM = oADoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
oBOM.HideSuppressedComponentsInBOM = True
Dim oStrBOMView As BOMView = Nothing
For Each oBOMView As BOMView In oBOM.BOMViews
If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
oStrBOMView = oBOMView
Exit For
End If
Next oBOMView
If oStrBOMView Is Nothing Then Return
Dim sFileName As String = ThisDoc.PathAndFileName(False) & ".xlsx"
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Add("Table Name", "Assembly BOM - Structured All Levels")
oStrBOMView.Export(sFileName, FileFormatEnum.kMicrosoftExcelFormat, oOptions)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)