Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: rprivittB3TTG

Here is something you can use to get the proper Mass value from the MassProperties object, and in the document units too, instead of the default 'database' units.  It checks to see if the Mass has been overwritten, and if True, it sets this to False, so it will show the real/actual Mass value.  Then it updated the model document, so it will recalculate, if necessary.  Once it retrieves this data, I included a message that will pop-up and tell you the results.  Then it will write the value to the user parameter you have.  Then it will expose that user parameter as a custom iProperty, so you can access this value through the iProperties instead of the parameters.  However, this will be a 'custom' iProperty, not the standard one, because the standard one generally returns the Mass in 'database' units by default, unless you have overwritten it.  This way nothing needs to be overwritten, and can remain 'live'.

Here is the iLogic rule code:

 

'get the document to work with
oDoc = ThisDoc.Document
Dim oMassProperties As MassProperties
Dim oParams As Inventor.Parameters
If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oDoc
	oMassProperties = oPDoc.ComponentDefinition.MassProperties
	oParams = oPDoc.ComponentDefinition.Parameters
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oADoc As AssemblyDocument = oDoc
	oMassProperties = oADoc.ComponentDefinition.MassProperties
	oParams = oADoc.ComponentDefinition.Parameters
Else
	'If this document is not either a Part or Assembly, exit the rule
	Exit Sub
End If

'get this document's units of measure for Mass
oUM = oDoc.UnitsOfMeasure
oMassUnits = oUM.GetStringFromType(oUM.MassUnits)

'convert the Mass from 'database' units to document units
If oMassProperties.MassOverridden = True Then
	oMassProperties.MassOverridden = False
End If
oDoc.Update
oMass = oUM.ConvertUnits(oMassProperties.Mass, UnitsTypeEnum.kDatabaseMassUnits, oMassUnits)

MsgBox("Mass = " & oMass & " " & oMassUnits, vbInformation, "Mass Data")

Try
	'find the parameter
	oParam = oParams.Item("NewMASS")
	'make sure the units are correct
	oParam.Units = oMassUnits
	'update its value
	oParam.Expression = oMass.ToString
Catch
	'the parameter wasn't found, so create it
	oParam = oParams.UserParameters.AddByExpression("NewMASS", oMass.ToString, oMassUnits)
End Try

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)