• Blog posts

    Bio

    By Clint Brown

    Have you ever wanted to quickly export your Inventor Bill of Materials (BoM) using iLogic?

    Look no further, I have adapted some code from the Inventor API samples to export an Inventor Assembly BoM, the code checks that you are in an Inventor Assembly file (.iam) and then exports a Structured BoM (All Levels) to the "C:\temp\"  location.

    The location that the BoM is published to can be edited by simply editing the "oPath" below. I have added commentary on the code below, and included the code for exporting a "Parts Only" BoM as well (this is commented out).

    SyntaxEditor Code Snippet

    'Adapted from Inventor API Samples by Clint Brown @ClintCadline
    'Originally posted on Cadline Community https://www.cadlinecommunity.co.uk/hc/en-us/articles/212849309 oDoc = ThisDoc.ModelDocument If oDoc.DocumentType = kPartDocumentObject Then MessageBox.Show("You need to be in an Assembly to Export a BOM", "Cadline: iLogic - BOM Publisher") Return End If oDoc = ThisApplication.ActiveDocument Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM '========================================================================================== 'You can change the output path by editing oPATH below oPATH = ("c:\temp\") 'If you change this, remember to keep a \ at the end '========================================================================================== 'STRUCTURED BoM =========================================================================== ' the structured view to 'all levels' oBOM.StructuredViewFirstLevelOnly = False ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True Dim oStructuredBOMView As BOMView oStructuredBOMView = oBOM.BOMViews.Item("Structured") ' Export the BOM view to an Excel file oStructuredBOMView.Export (oPATH + ThisDoc.FileName(False) + ".xls", kMicrosoftExcelFormat) '========================================================================================== 'PARTS ONLY BoM =========================================================================== '' Make sure that the parts only view is enabled. 'oBOM.PartsOnlyViewEnabled = True 'Dim oPartsOnlyBOMView As BOMView 'oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only") '' Export the BOM view to an Excel file 'oPartsOnlyBOMView.Export (oPATH + "BOM-PartsOnly.xls", kMicrosoftExcelFormat) '========================================================================================== i = MessageBox.Show("Preview the BOM?", "Cadline: iLogic - BOM Publisher",MessageBoxButtons.YesNo) If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If If launchviewer = 1 Then ThisDoc.Launch(oPATH + ThisDoc.FileName(False) + ".xls")