I was just recently working on a program that needed to output the volume.
In addition to using the UnitsOfMeasure object to convert units, as
Venkatesh demonstrated, you can also use it to format strings for output to
the end-user. Here's some code that creates a string containing the volume.
The Volume property will always return the volume in cm^3. This will create
a string that will show the volume in whatever units the end-user has
currently chosen as the distance units they want to work in. Because there
isn't a predefined unit for volume this defines one using a string, (i.e.
"in ^3"). It gets the current length unit as a string and then creates a
string that defines a volume and uses that as input to the
GetStringFromValue method to create a string formatted to show the end-user.
' Get the current length unit as a string.
Dim strLengthUnit As String
strLengthUnit = oUOM.GetStringFromType(oUOM.LengthUnits)
Dim strResult As String
strResult = oUOM.GetStringFromValue(oMassProps.Volume, strLengthUnit & "^3")
Autodesk Inventor API
wrote in message news:email@example.com...
How can i format the volume of the code bellow to be displayed in mm^3 and
Public Sub GetPartMassProps()
' Set a reference to the part document.
' This assumes a part document is active.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
' Set a reference to the mass properties object.
Dim oMassProps As MassProperties
Set oMassProps = oPartDoc.ComponentDefinition.MassProperties
' Set the accuracy to medium.
oMassProps.Accuracy = k_Medium