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.
NEED SOME EXPLANATION
papawo
Member, Developers Posts: 206 PRO
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646Yup! If you run the feature from the UI, the defaults in `isBidirectionalSolidExtrudeDef ` will overwrite `EXTRUDE_DEFAULTS_3 `. If you call the feature from inside another feature, all of the parameters that you don't specify will be filled in with the values from `EXTRUDE_DEFAULTS_3 `.
Maybe it'll be easier to think of the parameters as being set by a series of events:- User opens the UI.
- Every single parameter mentioned in the precondition is set to its UI Default, (not the defaults written by the map at the end, the defaults given in the annotations in the precondition. Edit: If no default is given in the annotation, a default is assigned based on type. e.g. booleans default to false, enums default to the first in the list, strings default to blank etc.).
- Any parameters that have not been mentioned somewhere in the precondition are set to the Defaults found in the map at the end (the defaults defined by the map that you are asking about.)
export const printBoolean = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "My Boolean", "Default" : true } definition.myBoolean is boolean; } { println(definition.myBoolean); }, {myBoolean : false});
When you open the UI, the checkbox for myBoolean is set to true, so the feature will print 'true'. If you are writing some other feature that uses printBoolean(...), you'll see the following behavior:printBoolean(context, id + "p1", { "myBoolean" : true }); // prints 'true' printBoolean(context, id + "p2", { "myBoolean" : false }); //prints 'false' printBoolean(context, id + "p3", {}); // prints 'false' (UI defaults are not used, because user is calling from inside FS, not from UI)
To simplify and wrap up: there is really no reason to write a map of defaults at the end of your feature. The cases where those defaults are actually applied are very rare.
Edit: cleared up how defaults are assigned by the UI if a parameter is mentioned in the precondition, but no default is assigned.Jake Rosenfeld - Modeling Team5
Answers
See this part of the documentation:
https://cad.onshape.com/FsDoc/library.html#defineFeature-function-map
Those defaults are used when the feature is called from FeatureScript. When your feature is called from the UI, the UI will set the value of input parameters before those defaults are applied. What type of parameter are you trying to set a default for?
If you want to set UI defaults, you can use a BoundSpec for ValueWithUnits types:
https://cad.onshape.com/FsDoc/library.html#module-valueBounds.fs
or you can do the following for strings, booleans, and enums:
https://forum.onshape.com/discussion/8257/in-precondition-how-do-i-set-a-default-value-for-a-boolean#latest
The set of defaults that you point out exists so that if someone were to call your feature like this:
Their blank map would be filled with the set of defaults that you've provided. If they provide some arguments, only the ones they haven't specified will be filled in from the defaults map. Generally, unless you expect that other people will be calling your feature from inside FeatureScript (instead of using it from their toolbar), there is no need to define defaults in the place you are wondering about.
It may be easier to explain if you post screenshots of what 'isBiDirectionalSolidExtrudeDef' and 'EXTRUDE_DEFAULTS_3' actually are. If any of the parameters you are trying to change using EXTRUDE_DEFAULTS_3 appear in isBidirectionalSolidExtrudeDef(...) the default will not apply because the parameter is being set by the UI, not the defaults map.
so any parameters that is in isBidirectionalSolidExtrudeDef will overwrite what is in EXTRUDE_DEFAULTS_3?
Maybe it'll be easier to think of the parameters as being set by a series of events:
- User opens the UI.
- Every single parameter mentioned in the precondition is set to its UI Default, (not the defaults written by the map at the end, the defaults given in the annotations in the precondition. Edit: If no default is given in the annotation, a default is assigned based on type. e.g. booleans default to false, enums default to the first in the list, strings default to blank etc.).
- Any parameters that have not been mentioned somewhere in the precondition are set to the Defaults found in the map at the end (the defaults defined by the map that you are asking about.)
Consider the following code examples to try and make this clearer:When you open the UI, the checkbox for myBoolean is set to true, so the feature will print 'true'. If you are writing some other feature that uses printBoolean(...), you'll see the following behavior:
To simplify and wrap up: there is really no reason to write a map of defaults at the end of your feature. The cases where those defaults are actually applied are very rare.
Edit: cleared up how defaults are assigned by the UI if a parameter is mentioned in the precondition, but no default is assigned.