Actually, here is a slightly more dynamic version of that same routine, which is not specific to just that one hard-coded instance property name. This version uses a Dictionary to keep track of potentially multiple instance properties by different names that may be found for each component in the row, and all of the different values for each. Then collects the instance property's name, along with all the values it finds under that same name in other components in that row, within one Dictionary entry. Then, sorts the values, as before. Then attempts to put those values into a column by the same exact name as the instance property's name, if one exists. This code could be modified to either let the user know that a column was not found for an instance property, and/or attempt to create the column. There are lots of possibilities.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
If oSheet.PartsLists.Count = 0 Then Exit Sub
Dim oPList As PartsList = oSheet.PartsLists.Item(1)
For Each oRow As PartsListRow In oPList.PartsListRows
If oRow.Custom Then Continue For
Dim oInsPropData As New Dictionary(Of String, List(Of String))
Dim oDBOMRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
If oDBOMRow.Custom Then Continue For
Dim oBOMRow As BOMRow = oDBOMRow.BOMRow
Dim oOccs As ComponentOccurrencesEnumerator = oBOMRow.ComponentOccurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.OccurrencePropertySetsEnabled = False Then Continue For
Dim oOPS As Inventor.PropertySet = oOcc.OccurrencePropertySets.Item(1)
For Each oProp As Inventor.Property In oOPS
If oInsPropData.Keys.Contains(oProp.Name) Then
oInsPropData.Item(oProp.Name).Add(oProp.Value.ToString)
Else
Dim oInsPropValues As New List(Of String)
oInsPropValues.Add(oProp.Value.ToString)
oInsPropData.Add(oProp.Name, oInsPropValues)
End If
Next 'oProp
Next 'oOcc
If oInsPropData.Count = 0 Then Continue For
For Each oEntry In oInsPropData
oEntry.Value.Sort
Dim oCol As PartsListColumn = Nothing
Try : oCol = oPList.PartsListColumns.Item(oEntry.Key) : Catch : End Try
If oCol Is Nothing Then Continue For 'or try to create/add the column
Try : oRow.Item(oCol).Value = String.Join(",", oEntry.Value) : Catch : End Try
Next
Next 'oRow
oSheet.Update
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
'If oDDoc.Dirty Then oDDoc.Save2(False)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)