Message 1 of 3
Can someone help me with code to add up the mass of selected parts within an assembly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an assembly where I would like to add the masses of selected or listed parts within an assembly. I tried Chat GTP first and this is what it gave me, it's working, as in iLogic is not returning an error when the rule is run, but the rule is not returning a valve?
' Get the active assembly document Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition ' Define the names of the two parts to include Dim part1Name As String = "Rectangular Profile Foundation Rebar-Top Mat Radial Bar.ipt" ' Change to match your part name Dim part2Name As String = "Rectangular Profile Foundation Rebar-Top Mat Radial Bar.ipt" ' Change to match your part name Dim part3Name As String = "Rectangular Profile Foundation Rebar-Top Mat Hoop Bar.ipt" ' Change to match your part name Dim part4Name As String = "Rectangular Profile Foundation Rebar-Bottom Mat Hoop Bar.ipt" ' Change to match your part name Dim part5Name As String = "Rectangular Profile Foundation Rebar-Ring Wall U Bar.ipt" ' Change to match your part name Dim part6Name As String = "Rectangular Profile Foundation Rebar-Ring Wall Hoop Bar.ipt" ' Change to match your part name Dim part7Name As String = "Rectangular Profile Foundation Rebar-Footing Dowels.ipt" ' Change to match your part name Dim part8Name As String = "Rectangular Profile Foundation Rebar-Ring Wall Dowels.ipt" ' Change to match your part name Dim totalMass As Double = 0 ' Loop through the components in the assembly For Each oOccurrence In oCompDef.Occurrences ' Check if the part is one of the two we want to include If oOccurrence.Name.Contains(part1Name) Or oOccurrence.Name.Contains(part2Name) Or oOccurrence.Name.Contains(part3Name) Or oOccurrence.Name.Contains(part4Name) Or oOccurrence.Name.Contains(part5Name) Or oOccurrence.Name.Contains(part6Name) Or oOccurrence.Name.Contains(part7Name) Or oOccurrence.Name.Contains(part8Name) Then ' Get the physical properties of the part Dim oPartProps As PropertySet = oOccurrence.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item("Design Tracking Properties") Dim partMass As Double = CDbl(oPartProps.Item("Mass").Value) ' Add the mass to the total totalMass += partMass End If Next iProperties.Value("Custom", "WOR") = totalMass