Best "agile" approach to create a CASE as if i was programming in language code

Hi all,

I was wondering, what is the best approach to program a CASE ?

If you see my graph it’s pretty heavy

FYI : What i’m attempting to do is a specific rotation depending of the type that is in the description of the structure part

There’s some pretty simple DesignScript syntax that you can use in a Code Block.

Generally:
conditionToCheck ? trueValue: falseValue

Example:

You can nest these statements, but eventually it might become unreadable. At that point you might consider just writing some if-elif-else statements in a Python node.

2 Likes

Sweet ill.dig into it

And find out how to do this with strings

Rather than it statements, try a dictionary.

Hard code it once with all the possible names as keys and the rotation as value, then pull the values using the description and you’re all set.

1 Like

String.Contains is not the best function to use. When you search for “T”, is it also found in “POTEAU INDENCIE” and “REDUIT” and more. It is better to use a function which will always give the desired result and that you feed it the values which you are certain about that this will happen. Maybe with String.StartWith, but when you have descriptions that start with “T”, it will also give false results. In you example, you better use the == node.

When looking for a series of texts, you can combine all instead of duplicate the nodes for each search string.

In this example you have a list of descriptions and you are looking for 4 values to be found. If you don’t set the level, you will compare one list to another list, where indice 1 is compared with indice 1 of the other list, and so on. If you set the second list to level 1, each item of the second list is processed apart, which result in (in the example) 4 lists of bools. The first list compares indice 1 to the whole other list, the second list compares indice 2 to the whole list, and so on.

Then it is not difficult to calculate the rotation:

If you want to combine this all in one Code Block, using Zachri’s tip:

Here you set the level of the search texts with the cartesian replication notation <1> at the end of the variable ‘search’.

3 Likes

Rethinking, I am not sure if my example will help you, because you create new lists with lists. Would be hard to work back to the original list.

A better approach is this:

Now you look for a text equal to one OR another.

But in some cases it must not be 0.0 but 180.0. You can replace one of the values with another structure of “a ? b : c”:

3 Likes

No thought to the dictionary method?

2 Likes

Yes, but I prefer the hard way first :stuck_out_tongue:

3 Likes

hi, another variation


occasionally, if I add a value to my data sample without reconnecting I get a weird alert message

cordially
christian.stan

Instead of asking if a is one of the options, ask if a is in the dictionary’s keys.

List.Contains(dict.keys(),a)?dict[a]:0;

3 Likes

always happy to learn, thanks for sharing
cordially
christian.stan

1 Like

List.Contains(dict.Keys,a<1>)?dict[a]:0;

cordially
christian.stan

2 Likes

Woaaa !
A lot of action during weekends !

Thanx a lot everyone - Ill test out these approaches and this thread is going to be usefull to help others for diffrent approaches for simple stuff in Dynamo.

2 Likes