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.
Featurescript Lookup Table in UI
Hugh_Goodbody
Member Posts: 41 PRO
I have a lookup table in a UI, I would like to poplulate the following UI field with data selected from the first field.
For example, user selects Pin diameter = 20mm, in the data table (I have this done), there are two entries for 20mm with two different OD options (35mm, 40mm), I would now like the next field in the UI to only display those two entries from the table - is this possible?


0
Comments
if (definition.fixingEnum == tubeFixing.FLANGE)<br> { <br> <br> <br> annotation { "Name" : "Flange", "Lookup Table" : flangeTable}<br> definition.flangeBore is LookupTablePath;<br> <br><br> annotation { "Name" : "Flange Front CC" }<br> isLength(definition.flangeClosedCentres, LENGTH_BOUNDS);<br> }Just to clarify, sounds like you're saying there are cases where you don't want OD to show. Are there cases where you do want it to show?
One possibility is changing "OD" from being part of the lookup table to being its own enum dropdown. That would allow it to show conditionally based on previous parameters, or could allow future parameters to show conditionally based on it (including showing different lookup tables). Though I'm not sure if this solves your problem, or if I fully understand yet.
If you explain what you're doing in more detail, including how you want to calculate your OD, myself and others may be able to give you a better idea of how you can proceed.
FRC Design Mentor - Team 1306 BadgerBots
The second way you can do it is using what I like to call the boomerang technique. It's a relatively new idea I came up with a month or so ago. The basic idea is to use a combination of hidden parameters and editing logic to control the visibility of one or more parameters in your annotation. In your case, this would probably work by creating a hidden Bore enum at the top of your precondition, then using that enum to drive the visibility of the corresponding look up tables. You would then need to select the appropriate enum option inside the editing logic based on whatever logic you want. You can see an advanced example of this in the Updated Spur Gear FeatureScript I posted yesterday; I can also provide simpler examples if you're struggling to understand what's going on. This would be by far the most user friendly solution, but I can understand why you might be hesitant to go down this path. Ultimately, the choice is up to you.
FRC Design Mentor - Team 1306 BadgerBots
// In FeatureScript preconditions, you aren't allowed to create one or more parameters with the same definition key (e.g. definition.flangeBore) // Note that this is separate from the user visible name defined under "Name", which can be duplicate across multiple parameters // Thus, I would recommend changing your code to look something like the following: if (definition.boreSize == BoreSize.BORE35 ) // enum table names generally have the first word capitalized, too { annotation { "Name" : "Flange", "LookupTable" : flangeTable35 } definition.flangeBore35 is LookupTablePath; } else if (definition.boreSize == BoreSize.BORE45 ) // note the use of else if { annotation { "Name" : "Flange", "LookupTable" : flangeTable45 } definition.flangeBore45 is LookupTablePath;<br>} // In order to use these inputs in the Feature Body later on, you can use an else if structure to collect from the appropriate table // based on your hidden enum. See the Variable Feature in the STD library for a good example of this structure. // Also, note that in order to hide a parameter, you'll need to use a UIHint // UIHints can be used to accomplish a wide variety of things - for a full list, see the FeatureScript Library documentation annotation { "Name" : "Bore size enum", "UIHint" : UIHint.ALWAYS_HIDDEN } // creates a hidden enum parameter definition.boreSize is BoreSize; // In order to get the editing logic working, you'll probably want to update the hidden BoreSize table whenever an input to it changes // This would look something like this: if {oldDefinition.input1 != definition.input1 || oldDefinition.input2 != definition.input2) // compute BoreSize and set definition.boreSize // The if condition keeps the calculations from running except when something that could actually affect it is changed. // Otherwise, it would get re-run every time a user makes any change to the UI, even if that change doesn't affect it at allFRC Design Mentor - Team 1306 BadgerBots