Message 1 of 18
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello together,
i found this code and i changed it a bit - works ok but only for parts in an assembly. If i have a sub-assembly with parts, i dont get the sum of this one.
I Need your help to modify the code that it will sum parts and sub-assemblies.
Thanks in advance...
Regards
Martin
'- - - - - - - - - - - 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 = "HK_Stand" '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("Project", "estimated cost") = 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 'Property In the Assembly xNumber = iProperties.Value("Project", "estimated cost") 'property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Project", "estimated cost") sumNumber = xNumber + yNumber 'set property values iProperties.Value("Project", "estimated cost") = Round (sumNumber,2) HK_Stand = sumNumber 'Else 'End If Next
Solved! Go to Solution.