Hi @edik_z,
I think this is what would work for you, since I use something very similar, though it didn't originate with me.
It works pretty well - I hardly ever have issues with it (not writing the correct quantities for example).
It will write a new iProperty, in your case called "ANZ" which will be filled with the total quantity of instances of that component in a given assembly.
You can then use that wherever you need, in a drawing for example or elsewhere.
Hope it is of good use.
Sub Main ()
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("This rule can only be run in an Assembly file - exiting rule...", "Error")
Exit Sub
End If
Dim customPropertyName As String = "ANZ"
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oAsmDef.Occurrences
Dim oDict As New Dictionary(Of String, Integer)
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
If Not oRefDoc.IsModifiable Then Continue For
If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then Continue For
If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then Continue For
Dim sPartNumb As String = oRefDoc.PropertySets("Design Tracking Properties")("Part Number").Value
Dim iCount As Integer = oOccs.AllReferencedOccurrences(oRefDoc).Count
If oDict.ContainsKey(sPartNumb) Then
oDict(sPartNumb) = oDict(sPartNumb) + iCount
'MessageBox.Show("1: " & sPartNumb & " " & iCount & " qty")
Else
oDict.Add(sPartNumb, iCount)
'MessageBox.Show("2: " & sPartNumb & " " & iCount & " qty")
End If
Next
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
If Not oRefDoc.IsModifiable Then Continue For
If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then Continue For
If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then Continue For
Dim sPartNumb As String = oRefDoc.PropertySets("Design Tracking Properties")("Part Number").Value
Dim iCount As Integer = oDict(sPartNumb)
If iCount = 0 Then Continue For
Dim oCustom As PropertySet = oRefDoc.PropertySets("Inventor User Defined Properties")
Try : oCustom(customPropertyName).Value = iCount
Catch : oCustom.Add(iCount, customPropertyName) : End Try
Next
End Sub