OK. Now that I know that you want to get Mass from the selected components, I can better help you achieve that. The following iLogic code is designed to check within your SelectSet for both ComponentOccurrence objects and for OccurrencePattern objects. And I changed the Type of data/object that is to be stored within the List object from String to ComponentOccurrence, so that it will be more useful to us in this task. If a regular ComponentOccurrence is found in the SelectSet, it is directly added to the List. But if a OccurrencePattern is found in the SelectSet, I start searching down within it to get the actual ComponentOccurrence objects, then add those to the List. Once everything within the SelectSet is sorted through and all the ComponentOccurrence objects have been added to the List, the code then moves on to loop through that list and extract the Mass of each component, then add the individual masses together to show you the total mass of all components selected. Then, because the mass is in 'database units' by default, the code checks if those units are the same as your document units. If they are not the same, it proceeds to convert the units to document units for you. Then uses a simple MsgBox to show you the result.
I hope this is closer to what you were trying to achieve.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim oADoc As AssemblyDocument = ThisDoc.Document
If oADoc.SelectSet.Count = 0 Then Exit Sub
Dim oSelectedOccs As New List(Of ComponentOccurrence)
For Each oObj In oADoc.SelectSet
If TypeOf oObj Is ComponentOccurrence Then
Dim oSOcc As ComponentOccurrence = oObj
oSelectedOccs.Add(oSOcc)
ElseIf TypeOf oObj Is OccurrencePattern Then
Dim oSOccPatt As OccurrencePattern = oObj
For Each oOccPattE As OccurrencePatternElement In oSOccPatt.OccurrencePatternElements
For Each oPattOcc As ComponentOccurrence In oOccPattE.Occurrences
oSelectedOccs.Add(oPattOcc)
Next
Next
End If
Next
If oSelectedOccs.Count = 0 Then Exit Sub
Dim oTotalMass, oMass As Double
For Each oOcc In oSelectedOccs
'this will be in 'database units', so units conversion may be needed
oMass = oOcc.MassProperties.Mass
oTotalMass = oTotalMass + oMass
Next
UOM = oADoc.UnitsOfMeasure
If UOM.MassUnits <> UnitsTypeEnum.kDatabaseMassUnits Then
oTotalMass = UOM.ConvertUnits(oTotalMass, UnitsTypeEnum.kDatabaseMassUnits, UOM.MassUnits)
End If
MsgBox("Total Mass of selected components = " & oTotalMass, vbInformation, "Mass Of Selected")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)