Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
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.

I want the choices inside the blue bracket to change the value of those inside of the grey bracket.
Tagged:
0
Best 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.0
Answers
-
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...
}
0 -
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.0
-
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.Evan_Reese said: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.0

