• Blog posts


    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")




  • Avatar
    Eric Small

    How do I modify this code to get the columns in the order that i want?

  • Avatar
    Clint Brown

    Hi Eric, check out this blog post: https://www.cadlinecommunity.co.uk/hc/en-us/articles/203364071, basically you need to customise your XML file

  • Avatar

    Hi! Thanks for this code! I tried to implement to Inventor 2017 but I get an error message. Can you tell me what I do wrong?


    System.ArgumentException: Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))

       bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

       bei Inventor.BOMViews.get_Item(Object Index)

       bei LmiRuleScript.Main()

       bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

       bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

  • Avatar
    Clint Brown

    Hi Martin

    There are 2 possible reasons. The code has not been copied and pasted perfectly (something is missing or has moved). Or you are not running it from an Assembly file. To help ensure that the code is easy to copy and paste into a Rule, I have attached the code in a text file to the article, this should make it a bit easier to use.

    Good luck


  • Avatar

    Hi Clint

    Instead of editing the output path in oPATH, can i get a code to popup a window to select path.


Please sign in to leave a comment.