SetListType Method


Sets the ListType of a paragraph.

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

Syntax

C#
public void SetListType(
	TextRange textRange,
	ListType listType
)
Visual Basic
Public Sub SetListType ( _
	textRange As TextRange, _
	listType As ListType _
)
Visual C++
public:
void SetListType(
	TextRange^ textRange, 
	ListType listType
)

Parameters

textRange
Type: Autodesk.Revit.DB TextRange
The given text range.
listType
Type: Autodesk.Revit.DB ListType
The ListType to set on the paragraph.

Remarks

This function applies the ListType to all paragraphs contained in the given range.

The following ListType options are available:

Set the list type to None if the paragraph should not be in a list.

The list type cannot be set to Mixed .

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

  • a paragraph that has None
  • or a list paragraph that has a lower indentation level, (i.e. is indented less)
Note that a list will continue uninterrupted after list paragraphs that have higher indentation level. These paragraphs are considered a 'sub-list'. Using SetIndentLevel(TextRange, Int32) it is therefore possible to create multi-level lists. Note that sub-lists can have their own sub-sub-lists. The nesting level is only limited by the maximum indent level.

FormattedText will keep lists consistent. That means that numbered paragraphs will automatically get sequential numbers or letters. It also means that if the list type of one paragraphs in the list is changed then that change is propagated to all the paragraphs in that list. Even if those paragraphs were not in the input text range. 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.

Examples

Copy C#
#region Autodesk.Revit.DB.FormattedText.AsTextRange()
public void AppendText(TextNote textNote)
{
    FormattedText formatText = textNote.GetFormattedText();

    TextRange range = formatText.AsTextRange();

    range.Start = range.End - 1;
    // set Length to 0 to insert
    range.Length = 0;
    string someNewText = "\rThis is a new paragraph\vThis is a new line without a paragraph break\r";
    formatText.SetPlainText(range, someNewText);

    // get range for entire text
    range = formatText.AsTextRange();
    range.Start = range.End - 1;
    range.Length = 0;
    string someListText = "\rBulleted List item 1\rItem 2\vSecond line for Item 2\rThird bullet point";
    formatText.SetPlainText(range, someListText);
    range.Start++;
    range.Length = someListText.Length;
    formatText.SetListType(range, ListType.Bullet);

    if (formatText.GetAllCapsStatus(range) != FormatStatus.None)
    {
        formatText.SetAllCapsStatus(range, false);
    }

    textNote.SetFormattedText(formatText);
}
#endregion
Copy VB.NET
#Region "Autodesk.Revit.DB.FormattedText.AsTextRange()"
        Public Sub AppendText(textNote As TextNote)
            Dim formatText As FormattedText = textNote.GetFormattedText()

            Dim range As TextRange = formatText.AsTextRange()

            range.Start = range.[End] - 1
            ' set Length to 0 to insert
            range.Length = 0
            Dim someNewText As String = vbCr & "This is a new paragraph" & vbVerticalTab & "This is a new line without a paragraph break" & vbCr
            formatText.SetPlainText(range, someNewText)

            ' get range for entire text
            range = formatText.AsTextRange()
            range.Start = range.[End] - 1
            range.Length = 0
            Dim someListText As String = vbCr & "Bulleted List item 1" & vbCr & "Item 2" & vbVerticalTab & "Second line for Item 2" & vbCr & "Third bullet point"
            formatText.SetPlainText(range, someListText)
            range.Start += 1
            range.Length = someListText.Length
            formatText.SetListType(range, ListType.Bullet)

            If formatText.GetAllCapsStatus(range) <> FormatStatus.None Then
                formatText.SetAllCapsStatus(range, False)
            End If

            textNote.SetFormattedText(formatText)
        End Sub
#End Region

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException This text range is empty. -or- This start index of this text range is not within the text range identifying the entire text. -or- The end of this text range is not within the text range identifying the entire text. -or- This list type is not valid to set on a paragraph.
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

See Also