Parses a formatted string into a number with units if possible.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- units
- Type: Autodesk.Revit.DB Units
The units formatting settings, typically obtained from Document.GetUnits() .
- unitType
- Type: Autodesk.Revit.DB UnitType
The target unit type for the value.
- stringToParse
- Type: System String
The string to parse.
- value
- Type: System Double %
The parsed value, in Revit's internal units. Ignore this value if the function returns false.
Return Value
True if the string can be parsed, false otherwise.Examples

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;
}

Private Function GetLengthInput(document As Document, userInputLength As [String]) As Double
Dim dParsedLength As Double = 0
Dim units As Units = document.GetUnits()
' try to parse a user entered string (i.e. 100 mm, 1'6")
Dim parsed As Boolean = UnitFormatUtils.TryParse(units, UnitType.UT_Length, userInputLength, dParsedLength)
If parsed = True Then
Dim msg As String = String.Format("User Input: {0}" & vbCr & vbLf & "Parsed value: {1}", userInputLength, dParsedLength)
TaskDialog.Show("Parsed Data", msg)
End If
Return dParsedLength
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentException | unitType is an invalid unit type. See UnitUtils.IsValidUnitType() and UnitUtils.GetValidUnitTypes(). |
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was NULL |
Autodesk.Revit.Exceptions ArgumentOutOfRangeException | A value passed for an enumeration argument is not a member of that enumeration |