How to write Logic in code blocks

hello, is there a way to write “OR” and “AND” statements in a code block? Like for example use it to search a list for one of the words that I put in the code block OR the other one. Similarly, look for Both words in a string, in the AND statement?

DS uses the same binary operators as C# so:

OR ||
AND &&
NOT !

Shortcuts are not supported.

Examples

a = true;
b= false;

c = a && b; //returns false as both statements need to be true
d = !a; //returns false (might be confusing, but say it in english: "NOT true", which is false!), similarly !false is true
e = a || b; //returns true as a is true
5 Likes

Its not working…

That won’t work as the context of the syntax is meaningless. I’m not sure if that nodes takes a list input, if it does change your codeblock to {"Boundary", "Masking"}; otherwise you will need to perform the operation using a two step process (i.e. Search for the first string then connect the output to another String Contains node to search for the other string.

Yeah, no it doesnt work. Ok I already had the two step process in place, just trying to simplify things. haha

if you only have two then run the two step process… if you’re looking 3 or 4 or X items this should help.

Im not getting it to work. Seems like dynamo is creating my code blocks with this bolt on list in my code blocks which is different than yours but I dont know why. Please advise.

This looks like a glitch in Dynamo itself.
Try restarting Dynamo in sandbox mode (not as a revit plugin) and giving it another go from scratch. If that doesn’t work post the results here and anyone else who opens it can check if it’s a coding issue on your end or an installation problem.

If it’d require a reinstall or other time consuming task or you need IT to run the install, you can also use the OOTB nodes which I call on in code blocks to produce the same result.

1 Like