Thanks @bradeneuropeArthur.
A bit of further scouting found this thread: https://forums.autodesk.com/t5/inventor-programming-ilogic/calculate-mass-of-parts-in-an-assembly/td...
I used some of the code that @WCrihfield posted, so thanks for that.
In the event that my code helps anyone else, here it is:
Sub Main()
'-------------------------------------------------------------------------
' Notes:
'
'-------------------------------------------------------------------------
' Vars:
'-------------------------------------------------------------------------
'
Dim oMass As Double
Dim strMass As String
' set number of decimal places:
Dim strDP As String = InputBox("Enter Number for DP " & strDP & "", "Set Decimal Places")
'
Dim intDP As Integer = (Convert.toInt32(strDP))
'
'-------------------------------------------------------------------------
' Get the active document:
'-------------------------------------------------------------------------
'
Dim oDocType = ThisDoc.Document.DocumentType
'
'=========================================================================
' Code for PART:
'=========================================================================
'
If oDocType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
'
Dim oMSs As ModelStates = oPartDoc.ComponentDefinition.ModelStates
If oMSs.MemberEditScope <> MemberEditScopeEnum.kEditActiveMember Then
oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End If
'
'-------------------------------------------------------------------------
' Iterate through Model States:
'-------------------------------------------------------------------------
'
Dim oOrigMS As ModelState = oMSs.ActiveModelState
'
For Each oMS As ModelState In oMSs
oMS.Activate
Dim oMSDoc As PartDocument = oMS.FactoryDocument
'oMSDoc.Rebuild2(True) 'helps ensure all updated, but may not be necessary (may take extra time)
oMass = oPartDoc.ComponentDefinition.MassProperties.Mass
oMass = oPartDoc.UnitsOfMeasure.ConvertUnits(oMass, oPartDoc.UnitsOfMeasure.MassUnits, Inventor.UnitsTypeEnum.kKilogramMassUnits)
oMass = Round(oMass, intDP)
'
Dim c_Mass As String = fnPropGetVal("c_Mass", "")
iProperties.Value("Custom", "c_Mass") = oMass & " kg"
Next 'oMS
oOrigMS.Activate
If oPartDoc.RequiresUpdate Then oPartDoc.Update2(True)
'
'=========================================================================
' Code for ASSEMBLY:
'=========================================================================
'
ElseIf oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
'
Dim oMSs As ModelStates = oAssemblyDoc.ComponentDefinition.ModelStates
If oMSs.MemberEditScope <> MemberEditScopeEnum.kEditActiveMember Then
oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End If
'
'-------------------------------------------------------------------------
' Iterate through Model States:
'-------------------------------------------------------------------------
'
Dim oOrigMS As ModelState = oMSs.ActiveModelState
'
For Each oMS As ModelState In oMSs
oMS.Activate
Dim oMSDoc As AssemblyDocument = oMS.FactoryDocument
'oMSDoc.Rebuild2(True) 'helps ensure all updated, but may not be necessary (may take extra time)
oMass = oAssemblyDoc.ComponentDefinition.MassProperties.Mass
oMass = oAssemblyDoc.UnitsOfMeasure.ConvertUnits(oMass, oAssemblyDoc.UnitsOfMeasure.MassUnits, Inventor.UnitsTypeEnum.kKilogramMassUnits)
oMass = Round(oMass, intDP)
'
Dim c_Mass As String = fnPropGetVal("c_Mass", "")
iProperties.Value("Custom", "c_Mass") = oMass & " kg"
Next 'oMS
oOrigMS.Activate
If oAssemblyDoc.RequiresUpdate Then oAssemblyDoc.Update2(True)
'
'=========================================================================
'
End If
'
End Sub
'
'======================================================================
'
'Use: Check for missing user defined property types
'Params: PropName - passed in name to check
' MissingSetVal - optional value to pass to the selected property set by default to empty string
' Doc - Name of the document to search for the attached property type defined as PropName
'Returns: A value held by the selected PropName object as an object - this could be text, bool or numeric.
'On Error: Returns -1. this can be tested and signalled to the user for further investigation.
'----------------------------------------------------------------------
Function fnPropGetVal(PropName As String,
Optional oMissingSetVal As Object = "",
Optional Doc As Inventor.Document = Nothing) As Object
'
Dim oReturnVal As Object
'
If Doc Is Nothing Then Doc = ThisDoc.Document 'set to current doc..
'
'define a property set object from the API
Dim CustomPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Inventor User Defined Properties")
'
'does the requested object exist?
Try
oReturnVal = CustomPropSet.Item(PropName).Value
Catch
'not found so create this object defined as PropName in the selected document and apply a value..
Dim oTransaction As Inventor.Transaction
Try
'Modify the current database and add a new param to user defined properties..
oTransaction = ThisApplication.TransactionManager.StartTransaction(Doc,"Create property """ & PropName & """")
CustomPropSet.Add(oMissingSetVal, PropName)
oTransaction.End
'
oReturnVal = oMissingSetVal
'Successfully created the object and set its value..
Catch
'failed to create - may be a permissions error..
If Not oTransaction Is Nothing Then oTransaction.Abort
oReturnVal = -1 'Unable to create.
End Try
End Try
'all done so..
Return oReturnVal
End Function
'
'======================================================================