Switch Statement

I’ve found C# has a switch case, I don’t remember if Python does too, and I see a node for if else logic. I was just wondering if anyone has made a Dynamo Node for a Switch Statement?
C# Case Statement : Switching Between Multiple Cases - Udemy Blog

The core equivalent is if, elif, else logic.
But there are a few different methods described on Stack that can be translated into the Dynamo environment for IronPython and CPython3.

Do you have a specific use case you are looking at?

I know there’s one coming up soon, just trying to do my prep work ahead of time, specifically I’ll be filtering through 59 drafting views, horizontal and vertical are a huge filter, but not the only case to be expected, I’ll see if I can start with something like
`

def f(x):
    match x:
        case 'horizontal':
            return 1
        case 'vertical':
            return 2
        case _:
            return 0   # 0 is the default case if x is not found

`
and then I can add to it as they become clearer

1 Like

A dictionary example, just in case it helps directly or indirectly for others viewing this topic.

1 Like

That’s better than I had in mind, thanks mate!

1 Like

I wanted to test it with text too and not just numbers. I’m pretty sure this will work for proof of concept, I may have to add some more filtering, but it may be in a node that feeds to this one, we’ll see how the logic flows

1 Like