Changing Text Element to Uppercase

I ran into a similar problem as indicated in this thread Change Text Note to Uppercase
I am trying to change all Text Notes to lower case, but I am stuck at the end. What is the ParameterName? I literally want all text notes to be changed.

Thank you for your help!

It’s not a parameter the way you’re thinking of it. Try using the OOTB TextNote.SetText node.

Seems like we are overthinking this a bit. In Rhythm there is a node for this. ( There is also a TextElement.ToLower node)

1 Like

Thank you very much, this works!

Here’s a similar script, for anyone stopping by.

Cheers.

Hello Everyone;

The two approaches I have seen on the internet either change the individual characters to upper case but destroy the formatting of the text note. Or they keep the formatting but use the “all caps” setting instead of changing the characters. Neither is what I wanted so here is a different approach that changes the characters and keeps the formatting.

ChangeCase.dyn (10.6 KB)

Here is the custom python node:

import clr
import sys

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")

import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

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

def ChangeCase (ftxt, ToUpper = True):
  #check type
  if not isinstance(ftxt, FormattedText): raise TypeError("Expected FormattedText Object")
 
  for inx in range (len (ftxt.GetPlainText())):
    trange = TextRange(inx,1)

    #Get Formatting
    ftxt_allcaps = ftxt.GetAllCapsStatus(trange) == FormatStatus.All
    ftxt_bold = ftxt.GetBoldStatus(trange) == FormatStatus.All
    ftxt_italic = ftxt.GetItalicStatus(trange) == FormatStatus.All
    ftxt_subscript = ftxt.GetSubscriptStatus(trange) == FormatStatus.All
    ftxt_superscript = ftxt.GetSuperscriptStatus(trange) == FormatStatus.All
    ftxt_underline = ftxt.GetUnderlineStatus(trange) == FormatStatus.All

    char = ftxt.GetPlainText(trange)
    if ToUpper:
      if char.islower(): 
        char = char.upper()
        ftxt.SetPlainText(trange, char)
        ftxt.SetAllCapsStatus(trange, ftxt_allcaps)
        ftxt.SetBoldStatus(trange, ftxt_bold)
        ftxt.SetItalicStatus(trange, ftxt_italic)
        ftxt.SetSubscriptStatus(trange, ftxt_subscript)
        ftxt.SetSuperscriptStatus(trange, ftxt_superscript)
        ftxt.SetUnderlineStatus(trange, ftxt_underline)
    else:
      if char.isupper(): 
        char = char.lower()
        ftxt.SetPlainText(trange, char)
        ftxt.SetAllCapsStatus(trange, ftxt_allcaps)
        ftxt.SetBoldStatus(trange, ftxt_bold)
        ftxt.SetItalicStatus(trange, ftxt_italic)
        ftxt.SetSubscriptStatus(trange, ftxt_subscript)
        ftxt.SetSuperscriptStatus(trange, ftxt_superscript)
        ftxt.SetUnderlineStatus(trange, ftxt_underline)

  return ftxt


TransactionManager.Instance.EnsureInTransaction(doc)

for item in TextItems:
	#elmt = doc.GetElement(eID)
	item.SetFormattedText (ChangeCase(item.GetFormattedText(), ToUpper = IN[1]))

TransactionManager.Instance.TransactionTaskDone()

OUT = TextItems

The basic idea is this:

  • Get the FormattedText object from the TextNote object.
  • For each character in the text string:
    1. Save applied formatting
    1. Change character as required. This removes formatting.
    1. Reapply formatting

Sincerely;
Michelle