Hi i’m trying to replace my text notes from P15, P16, P17, etc to (n+1) > so i get P16, P17, P18, etc.
I’m able to create a list to search and a list to replace but i doesnt seem to work.
Hi i’m trying to replace my text notes from P15, P16, P17, etc to (n+1) > so i get P16, P17, P18, etc.
I’m able to create a list to search and a list to replace but i doesnt seem to work.
Split your strings so the P is removed so you’re left with 15, 16 etc.
You can add 1 to this.
Then put the P back.
I just uploaded the dynamo to drive, what i mean is that it doesnt change any of the text notes, is like it doesnt find them.
Can you show your graph please?
that’s the graph and script
Can you post the graph image to the forum directly? Many of the regular forum users are away from their PC for the holiday so opening from a link is tough. Be sure to follow the instructions on exporting the workspace as an image.
No need for Python .
This can be done with just OOTB nodes.
Look for the String.Split
nodes.
Split by ‘P’
Feed the list with the numbers in a Code Block
n+1
then add the ‘P’ back in front.
Basicly what @Alien suggested / said.
EDIT
I just now saw the problem / issue isn’t really in changing the numbers, but updating the
Text Notes.
Tags are 100x better than text notes.
Can you consider using tags instead so they automatically update?
Ok, i came back, found out a way to do it, what i wanted to do is increase the number on the text on the case i need to put another text reference to mark a hole on a column or a beam to go trough pipes of any kind.
I can make a list with P+(n+1), the problem i found is that the index number of the list i make with the code block must much the index list of the textnote element, example “P18” at index 0 must much the same position of the textnote ID and the ID’s are sorted from min to max.
The problem comes when “P18” at index 0 doesnt much the Text of the texNote.
I also have to select the numbers by hand, it will be great to select by category and then filter only the P00 texts.
As long as you don’t filter, remove, sort, or alter the list sequence the updated value should revise the existing.
Also make sure you don’t build it in Auto as you’ll trigger an infinite loop.
Hi
a solution using regex and Python
import clr
import sys
import re
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
def searchReplace(textNote, searchN, replaceN):
formatText = textNote.GetFormattedText()
rangeFormat = formatText.Find(searchN, 0, True, True)
if rangeFormat.Length > 0:
formatText.SetPlainText(rangeFormat,replaceN)
textNote.SetFormattedText(formatText)
return textNote
#Preparing input from dynamo to revit
view = UnwrapElement(IN[0])
regex_filter = IN[1]
pattern = re.compile(regex_filter)
regex_filter = System.Predicate[System.Object](lambda x : pattern.search(x.Text) is not None)
all_notes = List[DB.Element](FilteredElementCollector(doc, view.Id).OfClass(TextNote).WhereElementIsNotElementType()).FindAll(regex_filter)
text_note_values_before = [x.Text for x in all_notes]
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for idx, textNote in enumerate(all_notes):
search_txt = pattern.search(textNote.Text).group(0)
curent_number = int(pattern.search(textNote.Text).group(1))
replace_txt = f"P{curent_number + 1:>02d}"
searchReplace(textNote, search_txt, replace_txt)
TransactionManager.Instance.TransactionTaskDone()
text_note_values_after = [x.Text for x in all_notes]
OUT = text_note_values_before, text_note_values_after