Loop through BOM-table

Loop through BOM-table

ChristianAndersenIsmyname
Advocate Advocate
397 Views
2 Replies
Message 1 of 3

Loop through BOM-table

ChristianAndersenIsmyname
Advocate
Advocate

Hi,

I'm having some issues with finding the Column name of my part list.

Could anyone help me out?

Dim Invapp As Inventor.Application = g_inventorApplication
Dim doc As Document = invapp.ActiveDocument

Dim osheet As Sheet = doc.sheets(1)
Dim myBOM As PartsList = osheet.PartsLists(1)

' Get column index (hard coded for now, but doesnt work if i reorder the columns)
Dim ItemColumn As Integer = 1
Dim QtyColumn As Integer = 2
Dim PartColumn As Integer = 3

' This for-loop doesn't find the column names
' Would be amazing to get rid of this and use column(ColumnName).index instead
'For i As Integer = 1 To myBOM.PartsListColumns.Count
'    If myBOM.PartsListColumns(i).ToString = "ITEM" Then ItemColumn = i
'    If myBOM.PartsListColumns(i).ToString = "QTY" Then QtyColumn = i
'    If myBOM.PartsListColumns(i).ToString = "PART NUMBER" Then PartColumn = i
'Next

'Loop through rows
For Each row As PartsListRow In myBOM.PartsListRows
    Dim item As String = row(ItemColumn).Value
    Dim qty As String = row(QtyColumn).Value
    Dim part As String = row(PartColumn).Value

    MsgBox(part) 'Surprisingly this works as I planned
Next

 

0 Likes
Accepted solutions (1)
398 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

PartsListColumn hasn't its string representation. Try the following change

If myBOM.PartsListColumns(i).ToString = "ITEM" Then ItemColumn = i
change to
If myBOM.PartsListColumns(i).Title= "ITEM" Then ItemColumn = i
Message 3 of 3

ChristianAndersenIsmyname
Advocate
Advocate

Thank you, this did the trick!

0 Likes