Replace mulitple values in list


#1

Hi all,

I have the attached script - it looks for doors and sets their acoustic value based on the acoustic value of their host… However being doors it’s not a straight comparison, the doors are 10dB less than their host.

So the script I have works, it looks for the smaller values first and replaces them with a value 10dB lower. What I’d like to know though is there a shorter quicker way of doing this so that I could have say 10 values to search for and 10 replacement values without having to search and replace each value individually?

Thanks for any pointers.

Cheers

K.
2015-09-04_22-27-47


#2

Keith,

You could remove the “dB” value from the end of the string, convert it to a number, subtract 10, convert it back to a string and concatenate the “dB” again.

2015-09-05_10-57-31


#3

Hi Dimitri,

Thanks for that - that works really nicely.

I finished off the script and in my sample project it works fine however when I apply it to a main project it seems to hang - I’ve left it running for quite a while but still just the timer icon… The problem seems to be right at the start when the script is trying to extract the dB rating ~(type parameter)~ from the Host Elements (walls).

I’ve taken just this portion of the script and tried running it but it just keeps hanging - is there something wrong with what I’m doing here or is it just going to take a very long time to run?

 

2015-09-05_13-54-57


#4

Keith, I’m not familiar with those custom nodes. Could you try with a few default nodes instead? The below takes less than 5 seconds for 2000 door instances:

2015-09-05_22-32-41

 


#5

Yes, the type or instance nose is from rhythm and will hang up on large workflows. I’ve been meaning to update this to include clockwork’s element.type node because it is more stable.


#6

thanks Dimitar, I tried something like this earlier but the Element.Host node didn’t seem to be working, again I assumed it was something I’d wired up wrong - updating the package seems to have sorted that though.

However I’m getting an error at the Element.Name node - see image below - I don’t think I’ve done anything wrong but perhaps you can adivse?

2015-09-05_17-49-07


#7

I tell a lie… Element.Host is back to returning an empty list again… This is one of the bits of Dynamo that as a ‘non programmer’ I find very frustrating as it’s hard to know if it’s a node issue or the way I’m putting them together! ;o)

2015-09-05_19-02-33


#8

You need to switch the “WallType.Name” node for a “WallTypeByName” node.

Not sure why the “Element.Host” is misbehaving. It is possible to have a few empty lists if somehow a door ends up without a host(very unlikely), or if you have a MIP classified as a door(also unlikely). If an empty list somehow does end up at the head of your input list, the element.name node ad get parameter nodes will fail. I’ve already reported this as a bug, so hopefully something will be done about that:

Here’s am example where I modeled an MIP as a door, and the name node fails:

2015-09-06_13-52-11

If there is such a case, we might try addressing the problem from the other end and instead extract all the doors from our walls with another nifty node called “Element.Inserts”:

 

2015-09-06_13-58-00

 

 


#9

Thanks Dimitar,

there were families included in the door category that aren’t hosted elements - this is something I’ll need to think about but will probably end up filtering the list at the start to remove these changing the category removes the error in the Element.Name node.

I’m still not getting any joy with the Element.Host - I’m thinking now that it’s maybe just not working right in the latest version of Dynamo (currently running the latest beta). However the Get.Host from the Blackbox package is working fine instead. Final version of this section of the full script looks like this…

Thanks again for all your help - it’s not easy at times knowing where things are going wrong or what is causing errors and without people like yourself on here giving up their time to help out I’d be a bit lost and probably very frustrated!

2015-09-06_13-01-25