What's new

Parameter units issue

eneyer

Member
Parameter units issue

I am getting the background values from the dimensions (not the display units) and I want to get/set using the display units.

Otherwise, there is a disconnect between the interfaces I am working with. This is a dynamic program, so I can’t be making assumptions or doing any manual unit conversions.

More or less, the unit are just for reference. I need to get the value that displays on the screen. It's strange seeing a parameter object with a different value than the one on the screen and no compliment display unit (although it's apparent that the number is off by a factor of 2.54).
 

shubhab

Member


Hi Eric,

The problem that you are seeing is because our API calculates and outputs results in model units rather than display units by default.
But, the actual calculation what's happening is correct.

So, although your display units is set to be inches, since the model units is cms (for all native Alibre designs), you are getting a different result which seems to be off by a factor of 2.54.

In order to overcome this problem, you will have to explicitly take care of this situation in your code, by finding out the model units and display units for that file and then multiplying or dividing by an appropriate factor.

This is a sample VB code snippet which will give you an idea as to how you can handle this situation:

Dim partDisplayUnits As ADUnits
Dim partModelUnits As ADUnits
Dim factor As Double
Dim sDisplayUnits As String

' Get the Model Units for the part file opened
partModelUnits = objDesignSession.DesignProperties.ModelUnits

' Get the Display Units for the part file opened
partDisplayUnits = objDesignSession.DesignProperties.LengthDisplayUnits

If partDisplayUnits = AD_INCHES Then
If (partModeltUnits = AD_CENTIMETERS) Then
factor = 0.3937008 ' because 1 inch = 2.54 cm
sDisplayUnits = "in"
End If
End If

Finally when you are outputting the results, you may want to multiply the value you output with the "factor" variable.

MsgBox( (objCircle.Radius * factor) & sDisplayUnits).

You may want to have a switch statement in your example for each Display unit.

Let me know if this answers your question.

Thanks,
Shubha,
Alibre, Inc.
 

eneyer

Member


Yes. that answers my question. If I understood this correctly, all models have a native length unit of cm. As long as I can assume that, I can convert them manually.

Likewise, what are the native units for other measurements?
like:
angles
mass
etc

Like I said, I am making a dynamic interface, so I can't miss any of them.

Thank you for the response
 

shubhab

Member


For native Alibre Files, the model units is cms and you can assume this in your application.
However, if you import files which were natively not created in Alibre Design, then the model units may vary.
So, if you will be using imported files created in other CAD packages, then you may want to first query for the model units and then appropriately convert them into Display units.

As far as native units for other measurements, I'll check with our Development team member and get back to you.

Thanks,
Shubha,
Alibre, Inc.
 

shubhab

Member


-The Model Units for Angles is radians. So, you may want to convert it to your display units.
-For Mass, the API outputs values in Kgs
-Volume in cm³ and Surface area in cm²
-Center of Gravity in cms too

Thanks,
Shubha,
Alibre, Inc.
 

eneyer

Member


I found that I can change the unit of the parameter when I get/set the value. Is there anything wrong with doing it this way or does this have a ripple effect?
 

shubhab

Member


If you use the appropriate conversion factors, then I don't think it will cause any problem.
Also, I am assuming that you are first getting the model units of the design and then converting it to the appropriate display units (as demonstrated in the code snippet in this thread)

Thanks,
Shubha
 
Top