Formatting Text Notes

Is there anyway to format text notes? I would like to do things like add tabs and underline for some text.

Short Answer: Probably with the FormattedText Class.

However, it is going to take some custom python or C# to work it out.

2 Likes

This is about as far as I’ve been able to get. It doesn’t throw out any errors, it also doesn’t do anything at all.

I eventually would like to get his to work with a for loop so I can get multiple text reformatted.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
element = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

makebold = TextNote.GetFormattedText(element[0])
makebold.SetUnderlineStatus(TextRange(0,10), True)

TransactionManager.Instance.TransactionTaskDone()

OUT = element[0]

See the remarks for GetFormattedText:

The returned object is not attached to the text note and modifying it will not modify the contents of the text note. After changes are made to the FormattedText, use SetFormattedText(FormattedText) apply those changes to the TextNote.

Try modifying your code to be something like this:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0])
element = elements[0]

TransactionManager.Instance.EnsureInTransaction(doc)
makebold = element.GetFormattedText()
makebold.SetUnderlineStatus(TextRange(0,10), True)
element.SetFormattedText(makebold)
TransactionManager.Instance.TransactionTaskDone()

OUT = element
1 Like

Thanks, I’ve found this thread and have tried working with both scripts to get it to work so I can get a list working. Your Script worked by the way.

[Add List: Numbers to Text Note]
(Add List: Numbers to Text Note)
It is saying, “File “”, line 27, in
AttributeError: ‘TextNote’ object has no attribute ‘SetformattedText’” and I’m not sure why.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
textInput = IN[0]

if not isinstance(textInput, list):
	textInput = [textInput]

TransactionManager.Instance.EnsureInTransaction(doc)

for textTitle in textInput:
	textTitle = UnwrapElement(textTitle)
	formatText = textTitle.GetFormattedText()
	textRange = formatText.AsTextRange()
	formatText.SetUnderlineStatus(textRange,True)
	textTitle.SetformattedText(formatText)

TransactionManager.Instance.TransactionTaskDone()

OUT = TextInput

Note the lowercase f instead of an uppercase F. Just replace this line:

textTitle.SetformattedText(formatText)

With this:

textTitle.SetFormattedText(formatText)

1 Like

Damn, typing is hard. Thank you.

1 Like