<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export BOM with options in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6426181#M65337</link>
    <description>&lt;P&gt;The Inventor API Help has a pretty decent example which demonstrates the .IAM Bom functionality. It would be pretty easy to augment the code you have with the logic of accessing the .IAM BOM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sample demonstrates the Bill of Materials API functionality in assemblies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT size="2"&gt;VBA Sample Code&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;Have an assembly document open and run the following sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub BOMQuery()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    Set oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Structured")
        
    Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description"
    Debug.Print "----------------------------------------------------------------------------------"

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        Set oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As ComponentDefinition
        Set oCompDef = oRow.ComponentDefinitions.Item(1)

        Dim oPartNumProperty As Property
        Dim oDescripProperty As Property

        If Typeof oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            Set oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            Set oPartNumProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2016 17:54:19 GMT</pubDate>
    <dc:creator>NSBowser</dc:creator>
    <dc:date>2016-07-08T17:54:19Z</dc:date>
    <item>
      <title>Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6415189#M65165</link>
      <description>&lt;P&gt;I found this excellent blog which shows how you can export a parts list from an .idw file to a pre-existing XLS file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://inventortrenches.blogspot.co.uk/2011/06/ilogic-export-parts-list-with-options.html" target="_blank"&gt;http://inventortrenches.blogspot.co.uk/2011/06/ilogic-export-parts-list-with-options.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to achieve a similar result with a BOM from a .iam file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far my iLogic code goes something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;ThisBOM&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;Export&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Structured&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;fileName1&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;kMicrosoftExcelFormat&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Which produces this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/252119iAE5B960B89BAA60F/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="BOM example.JPG" title="BOM example.JPG" width="751" height="320" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to export this data to a fancy looking pre-existing XLS file that has an 'Extended Cost' column J with the formula&amp;nbsp;=I2*D2 and a 'Total' cell underneath.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 15:33:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6415189#M65165</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-01T15:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6426181#M65337</link>
      <description>&lt;P&gt;The Inventor API Help has a pretty decent example which demonstrates the .IAM Bom functionality. It would be pretty easy to augment the code you have with the logic of accessing the .IAM BOM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sample demonstrates the Bill of Materials API functionality in assemblies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT size="2"&gt;VBA Sample Code&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;Have an assembly document open and run the following sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub BOMQuery()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    Set oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Structured")
        
    Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description"
    Debug.Print "----------------------------------------------------------------------------------"

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        Set oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As ComponentDefinition
        Set oCompDef = oRow.ComponentDefinitions.Item(1)

        Dim oPartNumProperty As Property
        Dim oDescripProperty As Property

        If Typeof oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            Set oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            Set oPartNumProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 17:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6426181#M65337</guid>
      <dc:creator>NSBowser</dc:creator>
      <dc:date>2016-07-08T17:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6428436#M65356</link>
      <description>&lt;P&gt;Hi, thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried running the rule but got the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error in rule program format:&lt;/P&gt;
&lt;P&gt;All other Sub's or Function's must be after Sub Main()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm running as an iLogic rule, should this be run as a macro?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 07:47:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6428436#M65356</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-11T07:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6428598#M65358</link>
      <description>&lt;P&gt;This should be run as VBA macro but it can work as iLogic code too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some simple adjustments should do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I corrected the error as the message stated in your reply&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;Error in rule program format:&lt;/P&gt;
&lt;P&gt;All other Sub's or Function's must be after Sub Main()&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And commented the debug messages because iLogic cant debug.. sadly.. &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You now have to choose what you want to do with it and tell it to do so. Because this does not do anything at the moment. If you want to export values into excel you should teach it how to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Sub  Main BOMQuery()
    ' a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' a reference to the BOM
    Dim oBOM As BOM
    oBOM = oDoc.ComponentDefinition.BOM
    
    ' whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    oBOMView = oBOM.BOMViews.Item("Structured")
        
    'Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description"
    'Debug.Print "----------------------------------------------------------------------------------"

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        oRow = oBOMRows.Item(i)

        'a reference to the primary ComponentDefinition of the row
        Dim oCompDef As ComponentDefinition
        oCompDef = oRow.ComponentDefinitions.Item(1)

        Dim oPartNumProperty As Inventor.Property
        Dim oDescripProperty As Inventor.Property

        If TypeOf oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            'Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
            '    oPartNumProperty.Value; Tab(70); oDescripProperty.Value
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            oPartNumProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            'Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
            '    oPartNumProperty.Value; Tab(70); oDescripProperty.Value
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 09:40:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/6428598#M65358</guid>
      <dc:creator>Jef_E</dc:creator>
      <dc:date>2016-07-11T09:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7244119#M73667</link>
      <description>&lt;P&gt;Thank you for your replies. Sorry for the huge delay, another big project came up and I had to put this on the back burner. I can get the code working for exporting to a new excel document, but really this isn't any different to the ThisBOM.Export iLogic function (minus the ability to re-order columns)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After hours of trawling forums and blogs, I am yet to find a way of exporting to an existing excel template from an assembly file, as is possible through the drawing parts list. Exporting from the parts list has one serious flaw, its not possible to get an all level structured BOM without manually expanding each row through the parts list editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is anybody doing something different or has a workaround/solution to either of these methods?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 08:06:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7244119#M73667</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-07-21T08:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7479398#M76012</link>
      <description>&lt;P&gt;Here's something from here:&amp;nbsp;&lt;A href="http://beinginventive.typepad.com/files/ExportPartslistToExcel/ExportPartslistToExcel.txt" target="_blank"&gt;http://beinginventive.typepad.com/files/ExportPartslistToExcel/ExportPartslistToExcel.txt&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let me know if it works, I'm trying to get something similar happening.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;'Expand legacy parts list to all levels
    Dim counter As Integer
    Dim k As Long
    counter = 1
    While counter &amp;lt; partList.PartsListRows.Count
        For k = counter To partList.PartsListRows.Count
        Dim orow As PartsListRow
        Set orow = partList.PartsListRows.Item(k)
        counter = k
        While orow.Expandable And Not (orow.Expanded)
            orow.Expanded = True
            counter = counter + 1
        Wend
        Next k
    Wend&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:53:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7479398#M76012</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-10-20T20:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Export BOM with options</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7479684#M76014</link>
      <description>&lt;P&gt;See this already existing thread. Adam has a proposal for a solution at the end of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-customization/thisbom-export-column-order-problem/m-p/4902030/highlight/true#M49080" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-customization/thisbom-export-column-order-problem/m-p/4902030/highlight/true#M49080&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 22:23:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/export-bom-with-options/m-p/7479684#M76014</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-10-20T22:23:40Z</dc:date>
    </item>
  </channel>
</rss>

