Skip to content

FormattedText

Public Class

FormattedText is used to create, edit and format text in a TextNote or to query the text and format properties of a TextNode

Inheritance Hierarchy

System.Object
Autodesk.Revit.DB.FormattedText

Namespace: Autodesk.Revit.DB

Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)

Syntax

public class FormattedText : IDisposable

The FormattedText type exposes the following members.

Constructors

Name

Description


Public Method
FormattedText.

Creates a new default FormattedText object, which contains only a carriage return character and has no formatting.


Public Method
Code Example
FormattedText(String)

Creates a new FormattedText object with unformatted text.


Properties

Name

Description


Public Property
IsValidObject

Specifies whether the .NET object represents a valid Revit entity.


Methods

Name

Description


Public Method
Code Example
AsTextRange

Returns a TextRange object that represents the entire text.


Public Method

Releases all resources used by the FormattedText


Public Method

Equals

Determines whether the specified object is equal to the current object.
(Inherited from Object)


Public Method
Code Example
Find

Returns a text range identifying the first occurrence of the given string within the text, starting from a given index.


Public Method
GetAllCapsStatus.

Returns whether All, None or a Mixed of characters in the entire text are in all caps.


Public Method
GetAllCapsStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are in all caps.


Public Method
GetBoldStatus.

Returns whether All, None or a Mixed of characters in the entire text are bold.


Public Method
GetBoldStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are bold.


Public Method

GetHashCode

Serves as the default hash function.
(Inherited from Object)


Public Method
GetIndentLevel

Returns the indent level of the paragraphs in the text range.


Public Method
GetItalicStatus.

Returns whether All, None or a Mixed of characters in the entire text are italic.


Public Method
GetItalicStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are italic.


Public Method
GetListStartNumber

Returns the list start number of the paragraphs in a given text range.


Public Method
GetListType

Returns the ListType of a paragraph.


Public Method

Returns the maximum allowed indent level


Public Method

Returns the maximum allowed list start number.


Public Method

Returns the minumum allowed list start number.


Public Method
GetPlainText.

Returns the entire text in a plain text form.


Public Method

Returns a substring of the text in a plain text form. The start and end of the substring is identified by a given TextRange.


Public Method
GetSubscriptStatus.

Returns whether All, None or a Mixed of characters in the entire text are subscripted.


Public Method
GetSubscriptStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are subscripted.


Public Method
GetSuperscriptStatus.

Returns whether All, None or a Mixed of characters in the entire text are superscripted.


Public Method
GetSuperscriptStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are superscripted.


Public Method

GetType

Gets the Type of the current instance.
(Inherited from Object)


Public Method
GetUnderlineStatus.

Returns whether All, None or a Mixed of characters in the entire text are underlined.


Public Method
GetUnderlineStatus(TextRange)

Returns whether All, None or a Mixed set of characters in a given text range are underlined.


Public Method

Sets the characters in the entire text to be in all caps or not.


Public Method
SetAllCapsStatus(TextRange, Boolean)

Sets the characters in a given text range to be in all caps or not.


Public Method

Sets the characters in the entire text to be bold or not bold.


Public Method
SetBoldStatus(TextRange, Boolean)

Sets the characters in a given text range to be bold or not bold.


Public Method
SetIndentLevel

Sets the number of tab stops that the paragraph should be indented.


Public Method

Sets the characters in the entire text to be italic or not italic.


Public Method
SetItalicStatus(TextRange, Boolean)

Sets the characters in a given text range to be italic or not italic.


Public Method
SetListStartNumber

Sets the list start number on the paragraphs in a given text range.


Public Method
Code Example
SetListType

Sets the ListType of a paragraph.


Public Method
SetPlainText(String)

Sets the entire text with the given text in a plain text form.


Public Method
SetPlainText(TextRange, String)

Sets the text with the given text in a plain text form in a range.


Public Method
SetSubscriptStatus(Boolean)

Sets the characters in the entire text to be subscript or not subscript.


Public Method
SetSubscriptStatus(TextRange, Boolean)

Sets the characters in a given text range to be subscript or not subscript.


Public Method
SetSuperscriptStatus(Boolean)

Sets the characters in the entire text to be superscript or not superscript.


Public Method
SetSuperscriptStatus(TextRange, Boolean)

Sets the characters in a given text range to be superscript or not superscript.


Public Method

Sets the characters in the entire text to be underlined or not underlined.


Public Method
SetUnderlineStatus(TextRange, Boolean)

Sets the characters in a given text range to be underlined or not underlined.


Public Method

ToString

Returns a string that represents the current object.
(Inherited from Object)


Remarks

An instance of FormattedText can be obtained from a TextNote (See TextNote.GetFormattedText()) or from a TextNode (See TextNode.GetFormattedText())

It is also possible to create a new instance of FormattedText and assign it to a TextNote (See TextNote.SetFormattedText()) This will result in a TextNote with text with the specified formatting applied

Formatted text can be used to:

  • Create formatted text for a new TextNote
  • Edit, Find and Replace text in an existing TextNote
  • Modify formatting of text in an existing TextNote
  • Or query the text and formatting a TextNote or a TextNode

Formatted text can be populated with plain text by using its constructor FormattedText(String) that takes a string, or by using the SetPlainText(String) method.

In addition, selected ranges of text can be added, removed, or replaced with the SetPlainText(TextRange, String) method by specifying a TextRange.

Use the Find(String, Int32, Boolean, Boolean) method to find the location of existing text.

Formatted text can have up to 30,000 characters. All characters, except the linefeed character (‘\n’), are allowed. This means that you should not use the ‘Environment.NewLine’ property, since that includes a linefeed character. Use the carriage return character (‘\r’) to terminate a paragraph. And use a vertical tab character (‘\v’) to create a new line without terminating the paragraph.

Formatted text allows for individual characters to be formatted. The following formatting can be applied.

  • Bold
  • Italic
  • Underline
  • Superscript/Subscript
  • All Caps

Use SetBoldStatus(TextRange, Boolean)) , SetItalicStatus(TextRange, Boolean)) , SetUnderlineStatus(TextRange, Boolean)) , SetSuperscriptStatus(TextRange, Boolean)) , SetSubscriptStatus(TextRange, Boolean)) , or SetAllCapsStatus(TextRange, Boolean)) to set the character formatting on a range of text.

Use GetBoldStatus(TextRange)) , GetItalicStatus(TextRange)) , GetUnderlineStatus(TextRange)) , GetSuperscriptStatus(TextRange)) , GetSubscriptStatus(TextRange)) , or GetAllCapsStatus(TextRange)) to get the character formatting of a range of text.

Text can be broken up in paragraphs. Paragraphs are terminated by a carriage return character (‘\r’).

Each paragraph can be indented several levels deep. For each additional level the indentation increments by one tab size. The total indentation is the product of a tab size and the indent level. Use SetIndentLevel(TextRange, Int32) to set the level of indenting up to a maximum indent level that can be obtained from

Use GetIndentLevel(TextRange) to find the indent level of a given range of text.

Note that the tab size is determined by the object that will contain the FormattedText.

In the case of a TextNote the tab size is a property of the TextNoteType returned from TextNote.TextNoteType. The tab size can be found by calling the Parameter.Guid. with TEXT_TAB_SIZE on the TextNoteType obtained from the TextNote

In the case of a TextNode the tab size can be obtained from its TabSize property

Formatted text can also be used to create numbered or bulleted paragraphs with the SetListType(TextRange, ListType) method.

The following ListType options are available:

Paragraphs with a ListType other than None are considered to be ‘list’ paragraphs. Consecutive list paragraphs with the same indentation level are treated as part of the same list. A list ends when a list paragraph is followed by

Note that a list will continue uninterrupted after list paragraphs that have higher indentation level. These paragraphs form a ‘sub-list’ of the list they interrupt. Sub-lists can have their own sub-sub-lists. The nesting level is only limited by the maximum indent level. Using SetIndentLevel(TextRange, Int32) it is therefore possible to create multi-level lists.

FormattedText will keep lists consistent. That means that list paragraphs will automatically get sequential numbers or letters. It also means that if the list type of one of the paragraphs in a list is changed then that change is propagated to all the paragraphs in that list. Note that this will not affect the list type of any nested sub-lists.

Use a vertical tab character (‘\v’) to insert a line without a bullet or number. Since this does not end the paragraph this will allow the list to continue to the next paragraph.

Example

public void FormatText(TextNote textNote)
{
// TextNote created with "New sample text"
FormattedText formatText = textNote.GetFormattedText();
// italicize "New"
TextRange range = new TextRange(0, 3);
formatText.SetItalicStatus(range, true);
// make "sample" bold
range = formatText.Find("sample", 0, false, true);
if (range.Length > 0)
formatText.SetBoldStatus(range, true);
// make "text" underlined
range = formatText.Find("text", 0, false, true);
if (range.Length > 0)
formatText.SetUnderlineStatus(range, true);
// make all text uppercase
formatText.SetAllCapsStatus(true);
textNote.SetFormattedText(formatText);
}