Please try this code:
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)
oLabels = New List(Of String)
oLabels.Add("Profile1")
oLabels.Add("Profile2")
oLabels.Add("Profile3")
oLabels.Add("Profile4")
oLabels.Add("Profile5")
oLabels.Add("Profile6")
oLabels.Add("Profile7")
oLabels.Add("Profile8")
oLabels.Add("Profile9")
oLabels.Add("Profile10")
oLabels.Add("Profile11")
RecursivelyProcessComponents(oOccs)
Dim oTotaliPartsWeight As Double = oWeightList.Sum
oTotaliPartsWeight = Round(oTotaliPartsWeight, 3, MidpointRounding.AwayFromZero)
MsgBox("Total Tool Weight = " & oTotaliPartsWeight & " kg", vbInformation, "Total Tool Weight")
Dim oCustom As PropertySet = oADoc.PropertySets("Inventor User Defined Properties")
Dim sNameProp As String = "Total Tool Weight"
Dim oProp As Inventor.Property
Try : oProp = oCustom(sNameProp) : oProp.Value = oTotaliPartsWeight & " kg"
Catch : oCustom.Add(oTotaliPartsWeight & " kg", sNameProp) : End Try
End Sub
Dim oWeightList As List(Of Double)
Dim oLabels As List(Of String)
Sub RecursivelyProcessComponents(oComps As ComponentOccurrences)
If oComps Is Nothing 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 TypeOf oComp.Definition Is WeldsComponentDefinition Then Continue For
Dim oCompDoc As Document = Nothing
Try : oCompDoc = oComp.Definition.Document : Catch : End Try
If oComp.IsiAssemblyMember Then
Dim oMember As iAssemblyMember = oComp.Definition.iAssemblyMember
oWeightList.Add(CDbl(oMember.Row.Item("Weight [Custom]").Value))
ElseIf oComp.IsiPartMember Then
Dim oMember As iPartMember = oComp.Definition.iPartMember
oWeightList.Add(CDbl(oMember.Row.Item("Weight [Custom]").Value))
Else
Dim bCCMember As Boolean = False
Try : bCCMember = oComp.Definition.IsContentMember : Catch : End Try
If bCCMember = True Then
Dim bCheck As Boolean = False
For Each sLabel In oLabels
If oCompDoc.DisplayName.Contains(sLabel) Then bCheck = True
Next
If bCheck = True Then
oWeightList.Add(oComp.MassProperties.Mass)
Else
Dim oPropValue As Object = Nothing
Try : oPropValue = oCompDoc.PropertySets.Item(4).Item("Weight").Value : Catch : End Try
Try : oWeightList.Add(CDbl(oPropValue)) : Catch : End Try
End If
Else
Dim Result As Integer
Result = MessageBox.Show("Would You Like To Input a Temporary Weight For This Part?", _
"No Part Weight Detected for '" & oComp.Name & "'", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
If Result = 6 Then
Dim Returnmyparam As String = InputBox("Input Weight in kg ", "Weight Input Prompt for '" & _
oComp.Name & "'", "")
Dim oWeightCProp As Inventor.Property = Nothing
Try
oWeightCProp = oCompDoc.PropertySets.Item(4).Item("Weight")
Catch
oWeightCProp = oCompDoc.PropertySets.Item(4).Add(CDbl(Returnmyparam), "Weight")
End Try
oWeightList.Add(CDbl(Returnmyparam))
ElseIf Result = 7 Then
ElseIf Result = 2 Then
Return
End If
End If
End If
Next
End Sub
End Class