2020 Class
Changes 0
C

FormattedText

Description:
FormattedText is used to create, edit and format text in a or to query the text and format properties of a
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:

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 GetMaximumIndentLevel. 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.

Inheritance Hierarchy:
System.Object
  Autodesk.Revit.DB.FormattedText
public class FormattedText : IDisposable
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);
}
Name Return Type Description
C FormattedText() None Creates a new default FormattedText object, which contains only a carriage return character and has no formatting.
C FormattedText(String) None Creates a new FormattedText object with unformatted text.
Name Return Type Description
M AsTextRange() TextRange Returns a object that represents the entire text.
M Dispose() None Releases all resources used by the
M Find(String, Int32, Boolean, Boolean) TextRange Returns a text range identifying the first occurrence of the given string within the text, starting from a given index.
M GetAllCapsStatus() FormatStatus Returns whether , or a of characters in the entire text are in all caps.
M GetAllCapsStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are in all caps.
M GetBoldStatus() FormatStatus Returns whether , or a of characters in the entire text are bold.
M GetBoldStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are bold.
M GetIndentLevel(TextRange) int Returns the indent level of the paragraphs in the text range.
M GetItalicStatus() FormatStatus Returns whether , or a of characters in the entire text are italic.
M GetItalicStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are italic.
M GetListStartNumber(TextRange) int Returns the list start number of the paragraphs in a given text range.
M GetListType(TextRange) TheListTypeof the paragraph. Returns the of a paragraph.
M GetMaximumIndentLevel() int Returns the maximum allowed indent level
M GetMaximumListStartNumber() int Returns the maximum allowed list start number.
M GetMinimumListStartNumber() int Returns the minumum allowed list start number.
M GetPlainText() string Returns the entire text in a plain text form.
M GetPlainText(TextRange) string Returns a substring of the text in a plain text form. The start and end of the substring is identified by a given .
M GetSubscriptStatus() FormatStatus Returns whether , or a of characters in the entire text are subscripted.
M GetSubscriptStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are subscripted.
M GetSuperscriptStatus() FormatStatus Returns whether , or a of characters in the entire text are superscripted.
M GetSuperscriptStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are superscripted.
M GetUnderlineStatus() FormatStatus Returns whether , or a of characters in the entire text are underlined.
M GetUnderlineStatus(TextRange) FormatStatus Returns whether , or a set of characters in a given text range are underlined.
M SetAllCapsStatus(Boolean) None Sets the characters in the entire text to be in all caps or not.
M SetAllCapsStatus(TextRange, Boolean) None Sets the characters in a given text range to be in all caps or not.
M SetBoldStatus(Boolean) None Sets the characters in the entire text to be bold or not bold.
M SetBoldStatus(TextRange, Boolean) None Sets the characters in a given text range to be bold or not bold.
M SetIndentLevel(TextRange, Int32) None Sets the number of tab stops that the paragraph should be indented.
M SetItalicStatus(Boolean) None Sets the characters in the entire text to be italic or not italic.
M SetItalicStatus(TextRange, Boolean) None Sets the characters in a given text range to be italic or not italic.
M SetListStartNumber(TextRange, Int32) None Sets the list start number on the paragraphs in a given text range.
M SetListType(TextRange, ListType) None Sets the of a paragraph.
M SetPlainText(String) None Sets the entire text with the given text in a plain text form.
M SetPlainText(TextRange, String) None Sets the text with the given text in a plain text form in a range.
M SetSubscriptStatus(Boolean) None Sets the characters in the entire text to be subscript or not subscript.
M SetSubscriptStatus(TextRange, Boolean) None Sets the characters in a given text range to be subscript or not subscript.
M SetSuperscriptStatus(Boolean) None Sets the characters in the entire text to be superscript or not superscript.
M SetSuperscriptStatus(TextRange, Boolean) None Sets the characters in a given text range to be superscript or not superscript.
M SetUnderlineStatus(Boolean) None Sets the characters in the entire text to be underlined or not underlined.
M SetUnderlineStatus(TextRange, Boolean) None Sets the characters in a given text range to be underlined or not underlined.
Name Return Type Description
P IsValidObject bool Specifies whether the .NET object represents a valid Revit entity.