Simplifying Code

dynamo

#1

Hello Everyone!

I love the clean and efficient solutions. I created a Dynamo script which works as expected, but I have a slight feeling, the code could be simplified.
Does anyone has a cleaner solution for this?


#2

I can at least tell you that you can probably remove the “==true” 's from the vode block. “IN1?” or “test2=IN2?” will probably do the job.


#3

Yes, you are right!
What I’m actually looking for is to find a way to use lists instead of 5 “String.Contains” and 5 tests.


#4

You probably can use a singular list but considering you’re running 5 different tests that are supposed to have 5 different outcomes I doubt that will be more efficient.


#5

Try cross product lacing on the string contains, then use a list transpose, and then get appropriate indices for your tests (ie:in[0], in[1]…).


#6

Thank you @JacobSmall, this got me to the right direction, but I got stuck again. :frowning: :smiley:

How can I get those “true”-s out from the sublists, so I can apply the test?
Other question:
When I have my sublists with “true”-s and “false”-es, is there a way to get the indicies of “true”-s for each elements? (there is only one or zero true in each list)


#7

List.IndexOf solves the second question.

Test them all using index notation.

Test[0]?ResultIfTrue0:Test[1]?ResultIfTrue1:null

Post your full graph and explain the end goal as this is starting to feel like you’re going about this in th longest way possible.


#8

:smiley: I’m just familiarizing myself with the opportunities. The end goal was those numbers. I just inserted them into a longer string.
Thank you for your help!
In my original script, I didn’t like to repeat “String.Contains”, and then test it 5 times. You got me to the right direction. My solution is below.![Solution|690x219]