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.
Very simple FS question - dropdown for selecting from multiple variable sets
romeograham
Member, csevp Posts: 676 PRO
I'm sure this is quite simple - but I'm having a hard time figuring it out on my own (extremely new to FeatureScript).
I would like to build on the strategy @Evan_Reese shows for an approach to global variables here to do the following:
I'd like to be able to pick from several standard specifications for a thing in a drop down in the UI. Then, based on the selection, different values would be assigned to my Variables.
If I select "Type 1" from the list, then the variables would be: A=1mm, B=1.5mm etc
If I select "Type 2" from the list, then the variables would be: A=2mm, B=3mm etc
Variables A, B are values from specification tables.
I understand how to create the variables and assign values etc...I imagine that I can easily create different sections in my FS that would have all the variables and their correct values. Something like this:
//Values for Type 1
v.A=1*mm;
v.B=1.5*mm;
//Values for Type 2
v.A=2*mm;
v.B=3*mm;
I don't know how to:
Thanks!
Romeo
I would like to build on the strategy @Evan_Reese shows for an approach to global variables here to do the following:
I'd like to be able to pick from several standard specifications for a thing in a drop down in the UI. Then, based on the selection, different values would be assigned to my Variables.
If I select "Type 1" from the list, then the variables would be: A=1mm, B=1.5mm etc
If I select "Type 2" from the list, then the variables would be: A=2mm, B=3mm etc
Variables A, B are values from specification tables.
I understand how to create the variables and assign values etc...I imagine that I can easily create different sections in my FS that would have all the variables and their correct values. Something like this:
//Values for Type 1
v.A=1*mm;
v.B=1.5*mm;
//Values for Type 2
v.A=2*mm;
v.B=3*mm;
I don't know how to:
- make the dropdown show up in my UI
- do the if/then statement that would point Onshape to the correct values for the variables based on which item I pick from the Dropdown.
Thanks!
Romeo
0
Comments
https://cad.onshape.com/documents/811c8ce57220b55278be3a71/w/bfc85c80c8b7f510f5ffc0a5/e/e6510002f399feed4152872e
Here is a more advanced, but more efficient way to do the same thing, I learned this from @Alex_Kempen:
https://cad.onshape.com/documents/811c8ce57220b55278be3a71/w/bfc85c80c8b7f510f5ffc0a5/e/596d7b61d9d6@Alex_Kempen
Remember, featurescript is very similar to JavaScript. If you watch some beginner tutorials for JS, it will help a lot. And of course, the forums are a great place too. Also, here is one of my earlier features that has lots of notes, it is not super efficient, but it has explanations: Topographinator
Creating a horizontal menu:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Thanks for the examples, I learned something new.
@romeograham
depending on your actual use-case, you may find that lookup tables are what you want. This is how the hole feature works to select your way down to the final hole spec by displaying different options depending on whether you pick ANSI or ISO and so on. I used this with the Captive Nut feature too. See the example from the official documentation here: https://cad.onshape.com/FsDoc/uispec.html
@MichaelPascoe thanks for the examples. I appreciate the simple example! The simple version is certainly what I was imagining (a simple way to pick different sets of variables - where I'd explicitly assign all of the options). I'll try to see if I can figure out how to get the "better" example to work for me too.
@Evan_Reese I found lookup tables too - but couldn't figure out how to get another level of options to work. I see that you're using them in Captive Nut. I'll look carefully and try to learn what's going on.
Thanks again for the help - I really value the work that you guys have put in to learning this language and making such great Custom FS's!
Romeo
I'm glad you're getting into FS!