Using iLogic to add up an assemblies component weights
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am looking to incorporate accurate weights for a large CAD Library without having completely accurate designs/models. I have added a custom iProperty to each part variation within each iPart (located in the iTables) in order to remedy this. My code currently allows for adding up all custom weights from all iPart components and subassembly components within the active assembly. However, there are complex components that I had to turn into iAssemblies containing a large number of iParts and non-iParts in order to function as needed. Therefore I am hoping to add a custom weight column to these iAssemblies themselves to overwrite the custom weights of the subcomponents within them. However, I need a code that will detect if an iAssembly contains the custom weight column and if so use the specified custom weights without also counting the subcomponent custom weights. But if the custom weight column is not detected, to add up the custom weights of the sub-components. I have attached the code I am currently utilizing, Please provide any help you can. Thank you.
Class ThisRule
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
oWeightList = New List(Of Double)
RecursivelyProcessComponents(oOccs)
Dim oTotaliPartsWeight As Double = oWeightList.Sum
MsgBox("Total iParts Weight = " & oTotaliPartsWeight, vbInformation, "Total iParts Weight")
End Sub
Dim oWeightList As List(Of Double) 'shared by both routines
Sub RecursivelyProcessComponents(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
If oComp.IsiPartMember Then
Dim oMember As iPartMember = oComp.Definition.iPartMember
oWeightList.Add(CDbl(oMember.Row.Item("Weight [Custom]").Value))
End If
If oComp.SubOccurrences.Count > 0 Then
RecursivelyProcessComponents(oComp.SubOccurrences)
End If
Next
End Sub
End Class