True/ false

i want to make an graph where it checks if a number is smaller then an other number.
so you have a:25, B:10, C: 20 and D: 30. Dynamo has to check if a is smaller then B, the conclusion is false. But when the answer is false i want that it will automatically check if a is smaller than C etc. And when its true it has to do another code that i still have to make.

I dont have a teacher who I can ask because he is also new with Dynamo. I have watched many tutorials but couldnt find a usefull one.

you already have the setup to generate the boolean values you need, next try using the logical operators in the Math > Logic section of the library.

this puzzle sounds like a general programming question more than a dynamo question specifically - have you looked into math/programming logic with true/false values? that might help you more than me just telling you the answer, or you could ask your teacher for help on that front.

now that i think about it, you might also want to look at the “if” conditional block.

As m-g stated you will need to utilize the “IF” or “Scope IF” node. I like Scope IF because you have the option to set lacing, but in your case either one will work. You will need to stairstep the process, checking from highest to lowest. Example: compare a to d first and if true feed that result through. If false compare a to c and if that’s true feed that result through and so on…

Something similar I have on one of my scripts. Checks to see if the value at index 3 and equal to blank, if false then return the value at index 3. if true then return whatever the result is of the next check and so on… if all are blank then it returns blank as the result.

Hope this helps!

my teacher is also new with dynamo so i guess i know even more then him now

1 Like

i understand some parts of it haha, if you have more tips or a more easy example let me know. but thanks anyway

This is basically the setup for your example

like this? sorry but i’m new haha

Sorry I probably confused you with my example as it was specific to what I needed in my script. My other reply should be how you need to set yours up.

thank you so much

1 Like

sorry but i have discussed it with some classmates, and still have some questions. sorry haha. i doesnt work like i think it should be.

line length a= 18(this is the lengt of a line which is drawn in revit)
Family b= 15
Family c= 20
Family d= 25

at particular lengths there has to be picked the right family. so the max length of family C is 20. so that is bigger then A(18). and when it is bigger it should pick family C etc. and when it is smaller it should check for the next number.

Ok, bit different than the other method, but this will be far easier with design script.

The code for an if statement in design script is as follows:

Test ? TrueResult : FalseResult ;
Note the question mark after the test, colon between the true and false result, and semi colon at the very end of the line (a must for all aspects of design script). My personal limit on if statement nesting is 6, but there are people out there who would argue that it should be capped at 1.

You have four variables.
The length of Object A (lenA).
Resulting Family B (famB).
Resulting Family C (famC).
Resulting Family D (famD).

The rest is a less than statement, the syntax of which is val1 < val2. Building the first test, lenA < 15 ? should be fairly straight forward.

Adding the true value should be as well: lenA < 15 ? famB :

However you don’t have a direct ‘false’ value to return, do you? Instead if the result is false you want to start a new test. This is why transitioning to writing code makes sense - we can nest our if statements. The syntax for such a nested statement where if false you do a new test is as follows:
test1 ? true1 : test2 ? true2 : allFalse ;

You can also insert another if statement in place for any of the values - that is you could have an if statement in your test, or an if statement in your true result, or the like. The can also go as deep as you want, but at some point it gets to be dumb and you want to use another method (Dictionaries, a while loop, etc.).

Anyway, you only have 3 values, so with this info we can start to finish off the statement, and add in the 2!d test to see if family C should be used, and the 3rd test to see if family D should be used.

lenA < 15 ? famB : lenA < 20 ? famC : lenA < 25 ? famD :

Now we are almost done, however there isn’t a clear indication on what to do if lenA is something else, say 762.9, and bigger than all values. We could just say ‘famD’ as the ‘false’ value for the second test if we knew this would never happen:

lenA < 15 ? famB : lenA < 20 ? famC : famD ;

Sometimes that makes sense, but with that value of 762.9 you wouldn’t want to use family D, and you have t convinced me that the 762.9 couldn’t happen. So instead we should continue to test until our upper limit of 25, return that value when true, and then finally come back with a result which lets the user know that they have broken the rules of the system and in my opinion will cause a warning so that the designer will review things carefully. I like to change data types to cause this, such as using a string when all other values are something else, which can be defined in design script by putting what you want to return in quotes like this “a string”. This is doubly handy as the value can be informative too, such as “Test failed. Variable lenA is too long for system. Revise your design.”

Since you’re a student I won’t be giving the final code here just yet - consider this your homework. All of the code can be generated via copy/paste of content above. Just watch your formatting, and know that while office hours are not consistent, the Dynamo community is here to help on the forum if you get stuck.

1 Like

i have made my own graph. and i have a question: as you can see in the picture i let dynamo check if the Length of the line is between other numbers. The fist check it isn’t between 10 and 15. but the second check it is between 15 and 25. so the IF node shows that number 7 till 10 is false. beacause in false there is a codeblock with 2. now i want that if its 2 it will make the family where the length is between 15 and 25. I thought maybe i can do at every if a other number for false. so false is 1 with a length between 10 and 15
2 with a length between 15 and 25
3 with a length between 25 and 30
4 with a lenth between 30 and 35
but it will display nr 4 now with the length of 22. that aint a problem if a know to make some nodes where it will make a family with the lowest number. so now with a length of 22 the lowest number is 2. so when its 2 it will pick family 2. but when the length is 26 it will see that the lowest number is 3 and then it will pick family 3. here is a port of the graph visable:

so the codeblock for false is at the first row 1 second row 2 etc.

If I am understanding correctly, your endgame is to have one result (either 1, 2, 3 or 4). You may need to change your logic. Instead of checking if 22 is greater than any number within the set of numbers, check to see if it is equal to any number in the set and use the List.AnyTrue node to return one result “true” or “false”. But ultimately, the answer has been provided in the above replies. You need to feed the result of one IF statement into the what to do if false of another IF statement and that result into the what to do if false of another IF statement and so on until all checks have been made. Your final IF statement will be the one result from all checks. Don’t feed your number set into the True input of the IF statement. You feed the family you want to use, so when the test returns a true result, the IF statement passes that family thru to the output.

FYI, to help simplify your graph, you can use the example below to create sets of numbers.

image

1 Like