Community
In an assembly, I am attempting to sum a user defined iProperty called "LENGTH" based on a user defined iProperty called "PART NAME". Each component in the assembly has an iProperty "PART NAME" value. There may possibly be two or more different "PART NAME" values that I will need to sum independently. I currently have the following code that I adapted to sum all of the lenths in the assembly, I am just unsure how to segregate the values by PART NAME.
'- - - - - - - - - - - find or create custom iProperty - - - - - - - - - - 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments Dim propertyName1 As String = "LENGTH" 'define custom property collection oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties") Try 'look for property oProp = oCustomPropertySet.Item(propertyName1) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName1) End Try Next '- - - - - - - - - - - sum the custom iProperty - - - - - - - - - - 'clear the custom property in the assembly iProperties.Value("Custom", "LENGTH") = 0 'set a reference to the assembly component definintion. 'This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences 'check for and skip virtual components '(in case a virtual component trips things up) If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then 'custom property in the assembly xNumber = iProperties.Value("Custom", "LENGTH") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "LENGTH") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "LENGTH") = sumNumber Else End If Next
Any advice is greatly appreciated.