String Replace - Sequence of variables and replace

Hi All,

Is there a way to make the script that searches through a sequence of “strings” and replaces them with a similar sequence? I’m trying to remove spaces after a number with a decimal point (project wide)

For instance: I current have “1. 8mm” and would like to change to “1.8mm”

Search for “. 1” replace with “.1”
Search for". 2" replace with “.2”
Search for". 3" replace with “.3”
Search for". 4" replace with “.4”
Search for". 5" replace with “.5”
Search for". 6" replace with “.6”
Search for". 7" replace with “.7”
Search for". 8" replace with “.8”
Search for". 9" replace with “.9”

Thanks in advance Dynamo guru’s!

This is what I currently have…but is only good for one set of string variables

@Ashton_at_Hierarchy Download the SwingNodes package

1 Like

Thanks @salvatoredragotta, that’s ideal!~

1 Like

@salvatoredragotta… I’m close… but what’s missing here?

Convert to string? What does the error say?

Warning: TextNote.SetText operation failed.
The input argument “text” of function Autodesk::Revit::Proxy::DB::TextElementProxy::Text::set or one item in the collection is null at line 214 of file d:\ship\2018_px64\source\detail\detaildbapi\gensrc\APITextElementProxy.cpp.
Parameter name: text

you are using square brackets instead of squiggly ones {}.

Not sure if that is it or not but square brackets are not allowed to form a list before 2.0 and I have not tried it yet. Do they form a list?

1 Like

Thanks Steven, using the most up to date Dynamo, which forces the square brackets instead of curly

1 Like

Thanks for bringing me up to speed on the square brackets.

This is not the most elegant solution but it will work for you. Its all OTB except for one Clockwork’s node at the very end.

1 Like

Wow! that’s elaborate… I’m very fresh to Dynamo so trying to learn on the fly. Thanks for all your help!

I just ran another test and it does not work if there is more than one period in the text string. I do not have time to figure it our right now.

If you are new what I did is a good learning opportunity for following data. You do not need to use it but it could help to look it over. All I did was remove all strings that did not have a number before the period and after the space. This figures out what is a period and a decimals. Feel free to PM me with any questions.

1 Like

Thanks mate, appreciate it. Script isn’t quite working yet, but sure is a good learning curve. Makes some sense!

Cheers,

You are getting a null for some reason . Can you try in Dynamo 1.3?

image

I just found String.ReplaceMultiple in clockwork package. you can give it a try too.

1 Like

Hi @salvatoredragotta … sorry 1.3 didn’t work either!

I’m going to give @Steven solution a shot early next week and will update you all then!

Thanks for all the help!

@Ashton_at_Hierarchy Please share your RVT file

@Steven & @salvatoredragotta - THE SOLUTION IS AS ABOVE! String.ReplaceMultiple worked like a treat.

Thanks for all your help!

If you are just doing that to get rid of the spaces, wouldn’t the default string replace work?

Is there a more complicated use case that this wouldn’t work for?

1 Like

I think @Ashton_at_Hierarchy is using this on a whole file. Doing what you did will remove the space at then of a sentence in addition to the space after the decimal.

2 Likes

Thanks for the input team, I think Steven is correct, we needed a way to limit it’s use, and the code above with string.replacemultiple was ideal for my specific purpose.

Thanks again!

1 Like