This should get you in the neighborhood. It's a quick and dirty iLogic rule that will run through an entire assembly, build out a dictionary of the virtual parts it finds, then export everything to an excel sheet. There are better ways to write it, but this seemed like the easiest for you to edit for your needs. Is this what you're looking for?
Sub Main()
'Dictionary of virtual parts w/ the partNumber as the key
Dim partList As New Dictionary(Of String, Object)
'Dictionary of virtual part info - currently qty and description
Dim part As Dictionary(Of String, Object)
'Loop through all individual parts
For Each comp As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences.AllLeafOccurrences
If Not comp.Suppressed AndAlso TypeOf comp.Definition Is VirtualComponentDefinition Then
Dim partNumber As String = comp.Definition.PropertySets("Design Tracking Properties")("Part Number").Value
'If we already have the part information, increment the quantity
If partList.ContainsKey(partNumber) Then
partList(partNumber)("qty") += 1
Else 'Gather and add part information
part = New Dictionary(Of String, Object)
part.Add("qty", 1)
part.Add("description", comp.Definition.PropertySets("Design Tracking Properties")("Description").Value)
partList.Add(partNumber, part)
End If
End If
Next comp
'Exit If we have no virtual parts
If partList.Count < 1 Then
MessageBox.Show("No virtual parts found in active assembly")
Exit Sub
End If
Dim outputFile As String = ThisDoc.Path & "\Virtual Part List.xlsx"
Dim excelApp As Object = CreateObject("Excel.Application")
Dim excelWorkbook As Object
excelApp.Visible = False
excelApp.DisplayAlerts = False
If Dir(outputFile) <> "" Then
excelWorkbook = excelApp.Workbooks.Open(outputFile)
excelWorkbook.Worksheets(1).activate
Else
excelWorkbook = excelApp.Workbooks.Add
End If
With excelApp
.Range("A1").Value = "Part Number"
.Range("B1").Value = "Quantity"
.Range("C1").Value = "Description"
Dim row As Integer = 2
For Each virtualPart As KeyValuePair(Of String, Object) In partList
.Range("A" & row).Value = virtualPart.Key
.Range("B" & row).Value = virtualPart.Value("qty")
.Range("C" & row).Value = virtualPart.Value("description")
row += 1
Next virtualPart
End With
excelApp.Columns.AutoFit
excelWorkbook.SaveAs(outputFile)
excelWorkbook.Close
excelApp.Quit
excelApp = Nothing
End Sub 'Main
If this solved your problem, or answered your question, please click Accept Solution.