Is there a way to change values of variables depending on an Enum selection?

I am relatively new to custom FeatureScripts and I am trying to create a list of variables. I would like the value of those variables to change depending on what choice I have made in the dropdown menu.

I want the choices inside the blue bracket to change the value of those inside of the grey bracket.

Best Answer

  • EvanReese
    EvanReese Member, Mentor Posts: 3,100 PRO
    edited November 2021 Answer ✓
    Actually, thinking more about it you could make each variable it's own map and just use the enum value as the key. It has to be made into a string to work, but I think I like this way a lot more. Here's an example.
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com

Answers

  • EvanReese
    EvanReese Member, Mentor Posts: 3,100 PRO
    edited November 2021
    There's probably a more elegant way, but you could do it with if statements.

    if (definition.myEnum == materialType.SHEET)
    {
    v.GA30 = 0.0120*inch;
    // and so on...
    }
    else if (definition.myEnum == materialType.STAINLESS)
    {
    v.GA30 = 0.0100*inch;
    // and so on...
    }

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • EvanReese
    EvanReese Member, Mentor Posts: 3,100 PRO
    edited November 2021 Answer ✓
    Actually, thinking more about it you could make each variable it's own map and just use the enum value as the key. It has to be made into a string to work, but I think I like this way a lot more. Here's an example.
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • david_dalton526
    david_dalton526 Member Posts: 3 ✭
    edited November 2021
    Actually, thinking more about it you could make each variable it's own map and just use the enum value as the key. It has to be made into a string to work, but I think I like this way a lot more. Here's an example.
    Thank you so much. I previously thought of using a Boolean expression but I knew there had to be a better way. I haven't messed with strings too much but, I can see that it is a very helpful tool to have.