Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Volume format

2 REPLIES 2
Reply
Message 1 of 3
Machado
179 Views, 2 Replies

Volume format

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.
2 REPLIES 2
Message 2 of 3
Anonymous
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.
Message 3 of 3
Anonymous
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report