Volume format

Volume format

Anonymous
Not applicable
334 Views
2 Replies
Message 1 of 3

Volume format

Anonymous
Not applicable
HI,everyone.

How can i format the volume of the code bellow to be displayed in mm^3 and m^3 ?

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

MsgBox "Volume: " & oMassProps.Volume
end sub

Thanks.
0 Likes
335 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You can use UnitsOfMeasure object to convert values from one unit system to
another. For example:

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

MsgBox "Volume: " & oMassProps.Volume

MsgBox "Volume (in^3): " &
oPartDoc.UnitsOfMeasure.ConvertUnits(oMassProps.Volume, "cm cm cm", "in in
in")

MsgBox "Volume (mm^3): " &
oPartDoc.UnitsOfMeasure.ConvertUnits(oMassProps.Volume, "cm cm cm", "mm mm
mm")
End Sub

wrote in message news:5200285@discussion.autodesk.com...
HI,everyone.

How can i format the volume of the code bellow to be displayed in mm^3 and
m^3 ?

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

MsgBox "Volume: " & oMassProps.Volume
end sub

Thanks.
0 Likes
Message 3 of 3

Anonymous
Not applicable
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")
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5200285@discussion.autodesk.com...
HI,everyone.

How can i format the volume of the code bellow to be displayed in mm^3 and
m^3 ?

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

MsgBox "Volume: " & oMassProps.Volume
end sub

Thanks.
0 Likes