Supporting imperial and metric units
Distance units support is included in Tekla.Structures.Datatype. Use the Distance structure to hold and convert distance units. Use the DistanceList structure to hold more than one distances in an array.
To set the current distance unit, set the Distance.CurrentUnitType property.
Distance.CurrentUnitType = Distance.UnitType.Millimeter;
To set whether fractional representation is used for US imperial units, set the
Distance.UseFractionalFormat property.
Distance.UseFractionalFormat = false;
You can use TeklaApplicationLibrary to check whether US imperial units are used.
if(TeklaStructures.Environment.UseUSImperialUnitsInInput)
{
Distance.CurrentUnitType = Distance.UnitType.Inch;
Distance.UseFractionalFormat = true;
}
Convert a string into a Distance using Parse or TryParse method. You can also specify the
number format provider and the default unit type using the overloads.
string text = "123.3 mm";
CultureInfo format = new CultureInfo("en-US");
Distance d = Distance.Parse(text, format);
Convert a Distance into a string using ToString method. You can also specify the format, the number format provider and the target unit type using the overloads.
Distance d = new Distance(123.3);
CultureInfo format = new CultureInfo("en-US");
string text = d.ToString(format);
Finally, you can access the distance directly using the Distance.Value and Distance.Millimeters properties.
Distance d = new Distance(123.3);
double value = d.Value;
double mm = d.Millimeters;