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.
a simpler way to define length parameter defaults
adamohern
Member, OS Professional Posts: 216 PRO
export const US_THICKNESS_BOUNDS = { "min" : -TOLERANCE.zeroLength * meter, "max" : 500 * meter, (meter) : [1e-5, .01905, 500], (centimeter) : 1.905, (millimeter) : 19.05, (inch) : .75, (foot) : 0.0625, (yard) : 0.02083333 } as LengthBoundSpec;
I don't understand LengthBoundSpec maps. All I want to do is set a default value for a field and, usually, allow it to be zero.
1) Why are min and max included as separate if they are also required in the (meter) value range? It seems redundant.
2) This seems like a lot of code for simply setting a default parameter. If I have to do this for every single input in my feature, I end up with tons of these things taking up the top 100+ lines of code, most of it fluff. Is there a cleaner way?
2
Comments
This was done quickly, it's possible that I don't need to convert units...
@traveler_hauptman's example is hypothetical, and doesn't work in FeatureScript. The reason it doesn't work (and may not ever work) is that we don't execute arbitrary FeatureScript code when extracting the parameters you want in your feature dialog. What is done is called "precondition analysis", where we look at your feature's precondition, resolve symbols where necessary, and expect those symbols to be defined in a standard way. A function call to Traveler's LSfactory is simply not one of those defined ways.
The result of LSfactory, if run, would be of a format that isLength would be fine with at runtime, which is why Traveler suggested it. Unfortunately, his code will never be executed at this phase. As soon as we see the unrecognized format, we fail to extract a specification of the feature dialog.
But there's good news!
We've changed the behavior of the length bound spec a bit, and when Onshape 1.54 comes out (our next release), you'll be able to set the min, max, and default for all units more concisely, even right in the parameter