Rerouting input data based on visual condition (value list)

Hi there,
I need to implement three different data manipulation scenarios (generate three different outputs). There should be a selection available for the end user. I wonder, is this the only way I can do it in Grasshopper+GhPython?


Many thanks for your advise,
Ilja

This is a reasonable way to approach this… why wouldn’t it be fine?

1 Like

@piac thank you for your reply. Since I am doing this for the first time I am curious are there any other methods :slight_smile:

if you’re working on a tiny screen, you can use this :wink:

out1 = palmar if (option == 0) else 1
out2 = dorsal if (option == 1) else 1
out3 = [palmar, dorsal] if (option == 2) else 1
1 Like

Since Python doesn’t know a “Switch”-statement, the common way in doing this is
using
if … :
elif …:
elif …:

In case you create high performing applications one day, this would reduce unnecessary conditional testing, because once it found one condition it doesn’t test for the remaining ones.
Furthermore I wouldn’t advise to write it like Amir proposed, unless for numbers, because its harder to read and it just can hold one statement. On the other hand, as long as you are doing scripting, nobody will care at all. So write it the way you like.

2 Likes

What Tom said. Just to add that you can use tuple unpacking to assign multiple variables on one line, like so:

In case terseness is a concern.

2 Likes

Very useful, thank you all! I’ll improve my script with elif statements and tuple unpacking as you suggested.