FormattedText Constructor (String)


Creates a new FormattedText object with unformatted text.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2017

Syntax

C#
public FormattedText(
	string plainText
)
Visual Basic
Public Sub New ( _
	plainText As String _
)
Visual C++
public:
FormattedText(
	String^ plainText
)

Parameters

plainText
Type: SystemString
The text in a plain text form.

Remarks

The given text should have no more than 30,000 characters. Line feed characters ('/n') are not allowed. An empty string is allowed.

Examples

CopyC#
public void ReformatText(TextNote textNote, string textToChange)
{
    String plainText = textNote.Text;
    FormattedText formattedText = new FormattedText(plainText);

    TextRange foundRange = formattedText.Find(textToChange, 0, false, true);
    while (foundRange.Length > 0)
    {
        formattedText.SetBoldStatus(foundRange, true);
        foundRange = formattedText.Find(textToChange, foundRange.End, false, true);
    }

    textNote.SetFormattedText(formattedText);
}
CopyVB.NET
Public Sub ReformatText(textNote As TextNote, textToChange As String)
    Dim plainText As [String] = textNote.Text
    Dim formattedText As New FormattedText(plainText)

    Dim foundRange As TextRange = formattedText.Find(textToChange, 0, False, True)
    While foundRange.Length > 0
        formattedText.SetBoldStatus(foundRange, True)
        foundRange = formattedText.Find(textToChange, foundRange.[End], False, True)
    End While

    textNote.SetFormattedText(formattedText)
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException plainText (excluding a carriage return character ('\r') at the end) has more than 30,000 characters. -or- plainText contains invalid characters such as a newline character.
Autodesk.Revit.ExceptionsArgumentNullException A non-optional argument was null

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →