UnitFormatUtils.TryParse
Description:
Parses a formatted string into a number with units if possible.
Parses a formatted string into a number with units if possible.
Overloads (4):
-
unitsThe units formatting settings, typically obtained from Document.GetUnits().
-
unitTypeThe target unit type for the value.
-
stringToParseThe string to parse.
-
valueThe parsed value, in Revit's internal units. Ignore this value if the function returns false.
Return Value
bool
True if the string can be parsed, false otherwise.
double GetLengthInput(Document document, String userInputLength)
{
double dParsedLength = 0;
Units units = document.GetUnits();
// try to parse a user entered string (i.e. 100 mm, 1'6")
bool parsed = UnitFormatUtils.TryParse(units, UnitType.UT_Length, userInputLength, out dParsedLength);
if (parsed == true)
{
string msg = string.Format("User Input: {0}\r\nParsed value: {1}", userInputLength, dParsedLength);
TaskDialog.Show("Parsed Data", msg);
}
return dParsedLength;
}
-
unitType is an invalid unit type. See UnitUtils.IsValidUnitType() and UnitUtils.GetValidUnitTypes().
-
A non-optional argument was NULL
-
A value passed for an enumeration argument is not a member of that enumeration