Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
731 Views, 4 Replies

Collect values of iProperties from sub components

I would like to loop through all referenced documents of any assembly and collect the values of an array of iProperties and present their totals as an iProperty in the assembly.

 

For example, the iProperties I'm searching through are called PUNCH, FORM, WELD

There are various sub-parts with these iProperties and they all have a numerical value (of type Text)

 

I wish to populate my assembly iProperties (PUNCH, FORM, WELD) with the combined totals of all the sub parts.

 

This is what I've tried so far (its incomplete as still need to make use of the array of iProp names) but it's failing at the first hurdle !! Can't get it to return the value from the function back to the sub. Can anyone help or suggest a more efficient way?

 

Its definitely finding values, I can see when I uncomment the message box in the function that shows the value of FORM 

 

Sub Main ()

Dim oDoc As Document = ThisApplication.ActiveDocument

If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub

 

 

Dim oADO As Inventor.ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

 

 

iProperties.Value("Custom", "FORM") = 0

iProperties.Value("Custom", "PUNCH") = 0

iProperties.Value("Custom", "WELD") = 0

 


For Each aDoc As Document In oDoc.AllReferencedDocuments

 

If aDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oAssmDoc As AssemblyDocument = aDoc
oDef = oAssmDoc.ComponentDefinition
ElseIf aDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc As PartDocument = aDoc
oDef = oPartDoc.ComponentDefinition
End If

' MyOperations = New String(){"FORM", "PUNCH", "WELD"}
'
' For Each op in MyOperations
' MsgBox(op)
' Next

If oDef.BOMStructure <> BOMStructureEnum.kPhantomBOMStructure 


      Dim Amount As Integer = oADO.AllReferencedOccurrences(aDoc).Count


      collectQuantity(aDoc,Amount,oLibraryPath)

End If

 

FORM_QTY = FORM_QTY + FORM

Next

 

iProperties.Value("Custom", "FORM") = FORM_QTY

 

End Sub

 

Function collectQuantity (aDoc As Document, Amount As Integer,oLibraryPath As String) As Double


Dim oPropsets As PropertySets = aDoc.PropertySets

Dim oCustomPropSet As PropertySet = oPropsets.Item("User Defined Properties")


Dim FORM As Double

Try
FORM =  oCustomPropSet("FORM").Value * Amount

'MsgBox(FORM)
Catch
FORM = 0
End Try

Return FORM

End Function