<?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 How to Export BOM Rows in Structured Order Based on Item Number? in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13179503#M174401</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am trying to export the rows of a Structured BOM from Autodesk Inventor in the order of &lt;STRONG&gt;Item Number&lt;/STRONG&gt; that I have already configured in the BOM. However, when I run my code, the rows do not export in the expected order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oBOM As BOM = oAsmDoc.ComponentDefinition.BOM
    oBOM.StructuredViewEnabled = True
    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	
	Call QueryBOM(oBOMView.BOMRows)
End Sub

Public Sub QueryBOM(oBOMRows As BOMRowsEnumerator)
	Static CurrenrRow As Integer = 3
	Dim i As Integer
	
	For i = 1 To oBOMRows.Count
		Dim oRow As BOMRow = oBOMRows.Item(i)
		Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		
		 MsgBox(oRow.ItemNumber &amp;amp; "_" &amp;amp; System.IO.Path.GetFileName(oCompDef.Document.FullFileName))
		If Not oRow.ChildRows Is Nothing Then
			Call QueryBOM(oRow.ChildRows)
		End If
	Next	
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Nov 2024 08:29:14 GMT</pubDate>
    <dc:creator>Dai_Tech</dc:creator>
    <dc:date>2024-11-28T08:29:14Z</dc:date>
    <item>
      <title>How to Export BOM Rows in Structured Order Based on Item Number?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13179503#M174401</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am trying to export the rows of a Structured BOM from Autodesk Inventor in the order of &lt;STRONG&gt;Item Number&lt;/STRONG&gt; that I have already configured in the BOM. However, when I run my code, the rows do not export in the expected order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oBOM As BOM = oAsmDoc.ComponentDefinition.BOM
    oBOM.StructuredViewEnabled = True
    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	
	Call QueryBOM(oBOMView.BOMRows)
End Sub

Public Sub QueryBOM(oBOMRows As BOMRowsEnumerator)
	Static CurrenrRow As Integer = 3
	Dim i As Integer
	
	For i = 1 To oBOMRows.Count
		Dim oRow As BOMRow = oBOMRows.Item(i)
		Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		
		 MsgBox(oRow.ItemNumber &amp;amp; "_" &amp;amp; System.IO.Path.GetFileName(oCompDef.Document.FullFileName))
		If Not oRow.ChildRows Is Nothing Then
			Call QueryBOM(oRow.ChildRows)
		End If
	Next	
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2024 08:29:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13179503#M174401</guid>
      <dc:creator>Dai_Tech</dc:creator>
      <dc:date>2024-11-28T08:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Export BOM Rows in Structured Order Based on Item Number?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13181949#M174439</link>
      <description>&lt;P&gt;Can anyone help me, please?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2024 16:16:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13181949#M174439</guid>
      <dc:creator>Dai_Tech</dc:creator>
      <dc:date>2024-11-29T16:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Export BOM Rows in Structured Order Based on Item Number?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13185489#M174453</link>
      <description>&lt;P&gt;Does your Top Assy BOM always reflect the correct order of the BOM Rows?&lt;BR /&gt;As oftentimes the sorting of the ChildRows from Top Assy BOM Rows is not the same with the how it is sorted in the Sub-Assy BOM.&lt;BR /&gt;&lt;BR /&gt;Below code is a modified one where you use the Sub-Assy BOM for the order of the item number.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
	
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oBOM As BOM = oAsmDoc.ComponentDefinition.BOM
	Call QueryBOM(oBOM, "")
	
End Sub

Public Sub QueryBOM(oBOM As BOM, TabSpace As String)

	oBOM.StructuredViewEnabled = True
	oBOM.StructuredViewFirstLevelOnly = False
	Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	
	Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows
	Dim i As Integer
	
	For i = 1 To oBOMRows.Count
		Dim oRow As BOMRow = oBOMRows.Item(i)
		Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		
		'MsgBox(oRow.ItemNumber &amp;amp; "_" &amp;amp; System.IO.Path.GetFileName(oCompDef.Document.FullFileName))
		Logger.Info(TabSpace &amp;amp; oRow.ItemNumber &amp;amp; "_" &amp;amp; System.IO.Path.GetFileName(oCompDef.Document.FullFileName))

		If Not oRow.ChildRows Is Nothing Then
			Dim oChildAsm As  AssemblyDocument = oRow.ComponentDefinitions(1).Document
			Call QueryBOM(oChildAsm.ComponentDefinition.BOM, TabSpace &amp;amp; "   ")
		End If
	Next	

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or if you opt to use how the ChildRows's Item Numbers, I have used a SortedDictionary object as intermediary.&lt;BR /&gt;Probably not the best way, but a possible workaround.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
	
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oBOM As BOM = oAsmDoc.ComponentDefinition.BOM
    oBOM.StructuredViewEnabled = True
    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	Call QueryBOM(oBOMView.BOMRows, "")

End Sub

Public Sub QueryBOM(oBOMRows As BOMRowsEnumerator, TabSpace As String)

	Dim oBOMROW_Dict As New SortedDictionary(Of String, BOMRow)
	
	For Each oBOMRow As BOMRow In oBOMRows
		 If Not oBOMROW_Dict.ContainsKey(oBOMRow.ItemNumber) Then
			 oBOMROW_Dict.Add(oBOMRow.ItemNumber,oBOMRow)
		 End If
	Next
	
	Static CurrenrRow As Integer = 3
	'Dim i As Integer

	For Each key In oBOMROW_Dict	
	'For Each oRow As BOMRow In oBOMRows

		Dim oRow As BOMRow = key.Value
		Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		
		Logger.Info(TabSpace &amp;amp; oRow.ItemNumber &amp;amp; "_" &amp;amp; System.IO.Path.GetFileName(oCompDef.Document.FullFileName))
		
		If Not oRow.ChildRows Is Nothing Then
			Call QueryBOM(oRow.ChildRows, TabSpace &amp;amp; "   ")
		End If
		
	Next
	
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2024 19:12:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13185489#M174453</guid>
      <dc:creator>jnowel</dc:creator>
      <dc:date>2024-12-01T19:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to Export BOM Rows in Structured Order Based on Item Number?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13186135#M174457</link>
      <description>&lt;P&gt;Thank you, sir, nice idea!!! However, your code has an issue with the "&lt;STRONG&gt;SortedDictionary&lt;/STRONG&gt; function" (e.g., 2.1 -&amp;gt; 2.10 results in: 2.1, 2.10, 2.2, 2.3...2.9).&amp;nbsp;But I've fixed it already. Thank you so much!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dai_Tech_1-1733121505268.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1440747i8778B64FCA8F91FB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dai_Tech_1-1733121505268.png" alt="Dai_Tech_1-1733121505268.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fixed&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dai_Tech_0-1733121450547.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1440746i8D456C23139AA66B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dai_Tech_0-1733121450547.png" alt="Dai_Tech_0-1733121450547.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 06:38:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-export-bom-rows-in-structured-order-based-on-item-number/m-p/13186135#M174457</guid>
      <dc:creator>Dai_Tech</dc:creator>
      <dc:date>2024-12-02T06:38:42Z</dc:date>
    </item>
  </channel>
</rss>

