Inventor Customization

Reply
Distinguished Contributor
Machado
Posts: 210
Registered: ‎12-15-2005
Message 1 of 3 (68 Views)

Volume format

68 Views, 2 Replies
06-08-2006 12:00 PM
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.
*Venkatesh Thiyagarajan \(Autodesk\)
Message 2 of 3 (68 Views)

Re: Volume format

06-08-2006 01:47 PM in reply to: Machado
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.
*Brian Ekins \(Autodesk\)
Message 3 of 3 (68 Views)

Re: Volume format

06-08-2006 03:05 PM in reply to: Machado
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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!