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,

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
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.


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.


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