String.Replace for multiple items with result transferred to another parameter

Hi All,
I am sorry to bring up the same topic but I could not Reply to the closed one with the same title. I hope you don’t mind.

My issue is that I am trying to classify rooms by finding Room Names and replacing them by their category (Classification/Department) so that I can push the new categorised value into the apporpriate parameter. Please, see image below:

I have read the discussion topic below, which has helped me a lot on compacting my routine.

String.Replace for multiple items

However, for an unknown reason, I am not succeeding on replacing all values as I would like it to. After I ran my routine, the values are transferred to the desired parameter. However, not all values were replaced by the equivalent ones. Rooms 6-8 and 25-29 should have all been assigned to different categories instead of having their name transferred into the parameter. See image below:

The routine that generates the above result was based on Dimitar’s suggestion in the post. It is the following:

I have also tried using Vikram’s coding solution, but it was not successful, probably because I am still trying to understand coding.

I have also tried Dimitar suggestion on using Clockwork node (List.ReplaceItemAtIndex) in the two first find and replace blocks (Short/Longest Lacing) but it resulted in having the room name pushed into the appropriate parameter instead. See images below.

So, I cannot understand why it is doing that in my first routine, nor understand how to fix it. I would appreciate some help. I thank you all in advance.

Kind regards, Haley.

You can try creating a dictionary to lookup your room names.

1 Like

Thank you very much, Nick, for your suggestion. If I understood well the dictionary suggestion has to have values manually assigned according to the number of rooms. So, this “formula”, has to be constantly maintained if the number of rooms changes. Is that right? If so, my main issue is that I have to create a routine that will nearly be maintenance free. As all projects are different, and I am not sure if all room names are going to exist in the project, I am trying to cater for as many names as possible so that the routine can automatically search and generate the new value as required without my having to make corrections to the routine. So, I am not sure how I could incorporate the dictionary suggestion to my routine. Any thoughts on that?

You can still use Dynamo to generate the Keys and Values for your dictionary. The dictionary is just a really efficient way of “replacing” your strings for multiple elements. How are you currently defining which Category goes with which Room?

Hi, Nick. Thanks again for the reply. They Categories are predefined by room functions in a project. So, it is by room name, and when the room name shows up, it should be replaced by its category. I will give your suggestion a go now, and hopefully, I will manage to have it all working as it should. I will keep you posted. Thanks again.

Hi, Nick. I don’t seem to find the last node that you have used in your routine. I have highlighted it in yellow in the image below. I am using Dynamo 1.0.1.1503 which is allowed in the company.

Package springnodes

Or don’t use spring nodes at all:

1 Like

Thank you, Andreas.

Thank you, Jostein. My main issue is still with the Code Block with the values {a,a,a,b,b,b,c,c,c,}. I don’t get it how Dynamo will know which one is which. I have 8 categories. How would this routine know how to assign “a” to the right room name?

I guess that is what a dictionary does for us. Think of an ordinary dictionary!
First you must establish the dictionary. the Keys list is like the words in a regular dictionary. And secondly the Values list represents the “meaning” of that word.
These two lists must correlate, so if you have a list of keys {b,j,c} then your list of values must read {“beauty”,“joy”,“computing”}

Now you have established the dictionary and can start to use it. If you now have a list of words in a random order you go through one by one and look it up in the dictionary and read the “meaning” of each word.

If you have a definition you could share with us, maybe we can solve it for you, but I for sure ain’t typing all those words manually! :wink:

Hi, Jostein. Thank you very much for the above explanation.
I tried to transfer what I have understood I should do with the information, and made the routine which I am attached to.
My main go is to transfer the “meaning” to another parameter. However, by just the running the routine without connecting it to the parameter, I realised that it was not working. Please, see image below:

DictionaryTest.dyn (21.0 KB)

Dictionary Test.rvt (1.3 MB)

I had managed to make it work through one of the first routines I posted above, but for a random reason, the routine started to generate crazy data. Every time I run it, I have inconsistent results. So, I thought I had it solved but there seems to be a sort of instability in Dynamo that does not make the results permanent. Anyway. Here is an image of my latest solution prior to giving it a go to the dictionary route:

I am still a long way to solving this routine. I do not get it why these issues are happening for it should have been a very simple solution to what I am trying to do. Using String.Searchfor.Replacewith should have solved it, but I am missing something in it and I do not know what it is. Anyway. Thank you for your help and hopefully, you will be able to help me with the dictionary one.

Something like this maybe? I think maybe I would have maintained the “database” somewhere else, like excel and just read from it in Dynamo, but what is done is done! :slight_smile:

DictionaryTest (1).dyn (25.8 KB)

2 Likes

Good morning Jostein.
Thank you so much for all the work and help. It seems that it is a quite stable routine, unlike the one I had before.
That goes to show that I need to learn more about coding to know the tricks “DSCore.List.Cycle({“UTILITIES”},Count(lst))”… in order to understand why things are not functioning as they should. Anyway.
I appreciated the effort and your help.
Kind regards, Haley.

Thank you, Nick, for pointing out to the right direction. :grinning: