UOM strikes again

UOM strikes again

Anonymous
Not applicable
495 Views
3 Replies
Message 1 of 4

UOM strikes again

Anonymous
Not applicable
Greetings All!

I'm attempting to determine the value of a specific table parameter.

Given: the IPT file kdefaultdisplaylengthunits = inches

Various results of expression values ...
?oTableParams.Item("tapholediameter").Expression = "0.375 in"

?oTableParams.Item("tapholediameter").Units = "in"

?oTableParams.Item("tapholediameter").Value = .9525 (I see Inventor stores the value preconverted to "cm", fine and dandy!)

'Now I want to return the value in inches ....
oUOM.GetValueFromExpression(oTableParams.Item("tapholediameter").Value,kinchlengthunits) = 2.41935

Why is the value returned converted again to "cm", not converted to "in"?

.375 in * 25.4 / 10 = .9525 cm
.9525cm / 25.4 * 10 = .375 in
.9525 * 25.4 / 10 = 2.41935 cm

Now this is interesting!

Thanks,
Brian
0 Likes
496 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
The GetValueFromExpression method takes a String as input and converts it to
database units. In the example you provided, VBA is converting the returned
Double value from the Value property into a String, (i.e. ".9525"). This is
treated the same as if you typed this into the Equation field of a
parameter. Since no unit is specified as part of the string, the
kInchLengthUnits is used to determine the unit type. This is then converted
to centimeters and passed back as a Double.

I think what you want to use is the ConvertUnits method of the
UnitsOfMeasure object. Below is a sample that demonstrates this. It will
get the value of the parameter named "d0" as inches. It doesn't matter what
the current units of the document are. The only requirement is that d0
represents a length. The first argument is the value you want to convert.
Remeber that the Value property of the Parameter object always returns the
result in database units, which for lengths is always centimeters. The
second argument specifies the units of the first arguments, which we know in
this case are always going to be centimeters. The last argument tells what
unit type you want the result to be. This can be any length unit.

Public Sub TestConvert()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParam As Parameter
Set oParam = oDoc.ComponentDefinition.Parameters.Item("d0")

Dim dValue As Double
dValue = oDoc.UnitsOfMeasure.ConvertUnits(oParam.Value,
kCentimeterLengthUnits, kInchLengthUnits)
End Sub
--
Brian Ekins
Autodesk Inventor API


wrote in message news:[email protected]...
Greetings All!

I'm attempting to determine the value of a specific table parameter.

Given: the IPT file kdefaultdisplaylengthunits = inches

Various results of expression values ...
?oTableParams.Item("tapholediameter").Expression = "0.375 in"

?oTableParams.Item("tapholediameter").Units = "in"

?oTableParams.Item("tapholediameter").Value = .9525 (I see Inventor stores
the value preconverted to "cm", fine and dandy!)

'Now I want to return the value in inches ....
oUOM.GetValueFromExpression(oTableParams.Item("tapholediameter").Value,kinchlengthunits)
= 2.41935

Why is the value returned converted again to "cm", not converted to "in"?

.375 in * 25.4 / 10 = .9525 cm
.9525cm / 25.4 * 10 = .375 in
.9525 * 25.4 / 10 = 2.41935 cm

Now this is interesting!

Thanks,
Brian
0 Likes
Message 3 of 4

Anonymous
Not applicable
Brian, thanks for the suggestion of using the ConvertUnits Method. The problem with ConvertUnits, is you must know the original UOM of the parameter being converted. The parameter list that I'm ripping through isn't static. The units of measure vary as well.

Is there a safer methodology, other than, case structuring for each possible UOM I may encounter? This appears as the only, albeit crude, solution using ConvertUnits with in a case structure.

Thanks again,
Brian
0 Likes
Message 4 of 4

Anonymous
Not applicable
Because of the consistent internal units you know what the UOM of the
parameter is. It will always be centimeters. Assuming that the parameter
is for a length, (instead of an angle, time, mass, etc.). Because of this
the second argument will always be kCentimeterLengthUnits for values you get
from the API.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:[email protected]...
Brian, thanks for the suggestion of using the ConvertUnits Method. The
problem with ConvertUnits, is you must know the original UOM of the
parameter being converted. The parameter list that I'm ripping through
isn't static. The units of measure vary as well.

Is there a safer methodology, other than, case structuring for each possible
UOM I may encounter? This appears as the only, albeit crude, solution using
ConvertUnits with in a case structure.

Thanks again,
Brian
0 Likes