Here is a 'recursive' example that will recurse down through all levels of components. This will record an entry for each occurrence in every level of the assembly that is from the content center. If you only need one entry line for each 'referenced document', not from each occurrence, then iterating through the AllReferencedDocuments collection may be a better fit, but would not include the names of the occurrences. There is a way to get what all occurrences reference a specific referenced document through, if that would suit your needs better. We simply don't have all the information about your intentions for this information yet.
Edit: Another thing to keep in mind is the BOM, and the settings that effect whether components will be included in it or not. The codes shown here so far do not obey or follow the BOM rules, other than Suppression. It pays no attention to the BOMStructure settings (Normal, Reference, Purchased, Phantom, etc.) of each component. If you need it to, then once again, the code would need to be further developed to enable that level of functionality.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
'initialize the global variable that was declared between routines
oReport = New System.Text.StringBuilder()
'write heading line into the report
oReport.AppendLine("Content Center Components Report:")
'call custom Sub routing to recurse through all components in all levels
RecurseComponents(oADoc.ComponentDefinition.Occurrences)
'show report message
MsgBox(oReport.ToString(), vbInformation, "CC List")
End Sub
'declare this variable between routines to make it globally accessible
Dim oReport As System.Text.StringBuilder
Sub RecurseComponents(occs As Inventor.ComponentOccurrences)
For Each oOcc As Inventor.ComponentOccurrence In occs
If oOcc.Suppressed Then Continue For
If TypeOf oOcc.Definition Is PartComponentDefinition Then
Dim oOccPDef As PartComponentDefinition = oOcc.Definition
If oOccPDef.IsContentMember Then
oReport.AppendLine(oOcc.Name & " --> " & _
oOcc.ReferencedDocumentDescriptor.FullDocumentName)
End If
End If
If TypeOf oOcc.Definition Is AssemblyComponentDefinition AndAlso
oOcc.SubOccurrences.Count > 0 Then
'call this same routine to run on the sub occurrences (recursion)
RecurseComponents(oOcc.SubOccurrences)
End If
Next
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)