Inventor Customization

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

Volume format

57 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 (57 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 (57 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube