“Dynamo Script to Automatically Renumber Text Notes Starting with Prefix (e.g., Z2_L0_) in Revit”

I have text notes in Revit that follow a pattern like Z2_L0_69, Z2_L0_70, etc.
I need to automatically change or renumber the numbers after the prefix (Z2_L0_).
I want to know if there is a Dynamo script or automation method to:

  • find all text notes with this prefix

  • extract the number

  • change or renumber it automatically

I have text notes in Revit that follow a pattern like Z2_L0_69, Z2_L0_70, etc.
I need to automatically change or renumber the numbers after the prefix (Z2_L0_).
I want to know if there is a Dynamo script or automation method to:

unlikely that someone has done exactly what you want, but yes, I’d say it is possible.

Could be better to use keynotes not text

1 Like

Hi Tobiyay, welcome :wave:
What have you tried so far?

You can collect all the text notes in a document

There are string nodes that can find, extract and modify the data as required
You can save back to the notes

This would be an excellent first project for a new Dynamo user

Please take the time to read How to get help on the Dynamo forums

2 Likes

Thanks for the reply!

You’re right — it might be a bit of an uncommon scenario.
Regarding keynotes: I initially thought of using them, but in my project, the text notes are being used for specific labeling that can’t easily be replaced with keynotes. Still, I’ll consider keynotes for future projects or if the script approach doesn’t work.

Would you have any recommendations on how to approach this in Dynamo, or any sample scripts for renumbering elements or text in a batch process?

Thanks again!

Thanks for the help, Mike!

I appreciate the advice and the welcome. So far, I’ve tried collecting the text notes using the All Elements of Category node, and I’ve used the TextNote.Text node to extract the text content. However, I’m having trouble incrementing or renumbering the numbers after the prefix (e.g., Z2_L0_69Z2_L0_70).

Do you have any suggestions on how to easily implement the logic for incrementing the numbers? I understand string nodes can help, but I’m unsure of the best way to split and manipulate the numbers.

Additionally, if you know of any example scripts that would help me get started with this task, I’d really appreciate it!

Thanks again for your time!

I’d suggest sharing what you have done & make any questions specific to a node or problem- you’ll get better answers with better questions

Also play around with some of the string nodes e.g splitting a string at a character, at a specific position

e.g split the string at a delimiter character, get the first 2 characters etc

1 Like

KINDLY HELP ME OUT !!! I AM NEW TO DYNAMO WHAT IS NEXT STEP

Hi @tobiyey908 thats multiline text, try something here
Revit_xpcm5WdvGU
a fast example

3 Likes

Thank you for the explanation! I Will give it a try and let you know if I have any further questions.

yoy are wlecome :wink: and maybe trim white space node could help as well maybe depends

1 Like

Some nodes which will help you out @tobiyey908 (in a somewhat sequential order from after your TextNote.Text

  1. String.StartsWith to identify an text which starts with your prefix.
  2. List.FilterByBoolMask to remove any text notes you don’t want to change. Be sure to use your text notes (from All Elements of Category), not the text itself (from TextNote.Text) as your list.
  3. TextNote.Text to get the text from the notes after filtering.
  4. String.Split to break each note into two parts at the “_” character.
  5. List.LastItem to get the ‘numbers’ which you’ll need to increment. Watch your lacing and list levels (you likely want @L2).
  6. String.ToNumber to convert the text "60" to 60 (colors change from orange to blue).
  7. + to add one to the value.
  8. + again with an empty string to convert the numbers back to text.
  9. List.ReplaceItemAtIndex to swap the last item in each sublist from the String.Split node with your incremented text.
  10. TextNote.SetText (or something similar - as I can’t remember the exact name, but if you find ‘text note’ in your library you’ll be able to identify it quickly).
3 Likes

Hi
For the TextNote positioning, I used the Coord property of the TextNote class from the API (packages almost certainly exist for this aspect).
Starting with a bounding box, if you have two numbers, you have a variation on X for the TextNote ordering.

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

ltextn=UnwrapElement(IN[0])

OUT = sorted(ltextn,key=lambda x:x.Coord.ToPoint().X)

Regards, Christian Stan

1 Like

Renumber Text Notes Starting with Prefix.dyn (45.6 KB)

"I tried running this script, but I’m getting several warnings. Could you please advise if anything needs to be modified or if there’s another approach I should try? I’ve attached the image and the .dyn file for your reference.

If there are any additional steps I need to follow, or if I should use a different node setup, kindly let me know. Your guidance will really help me move forward. Thank you in advance!"

@tobiyey908 It helps if you post what the warnings says and pin the preview bubbles.

1 Like

You have errors with these incoming connections; poor connection.

Regards, Christian Stan

edit: Note: This is a comparison based on diameter.

Edit 2: Here’s Python for handling different diameter types

import sys

OUT =[sum([j.count(i) for i in [chr(248),chr(216),"x",chr(8960)]]) for j in IN[0]]

Regards, Christian Stan

1 Like