Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

Default parameter syntax?

Emily_Qi_WangEmily_Qi_Wang Member Posts: 13 EDU
What is the syntax for setting default parameter values when defining a new feature?

I checked the doc files and SCOPE Weds slides that Kevin sent recently and didn't see this mentioned; apologies in advance if it's obvious and I missed it.

===

Code excerpt example (Also, are there code blocks in the Onshape forum discussion editor?)...

    precondition
    {
        annotation { "Name" : "Radius" }
        isLength(definition.radius, LENGTH_BOUNDS);
        annotation { "Name" : "Teeth" }
        isInteger(definition.teeth, POSITIVE_COUNT_BOUNDS);
    }

    // function action stuff here //

    { /* default parameters can go here?? */ });

===

For the default parameters block, I tried a few things:
* "definition.teeth" : 10
* definition.teeth = 10
* "Teeth" : 10 
* and so on...

Thanks in advance!

Comments

  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    The default is a map, so { teeth : 10 } should do it.  Also { 'teeth' : 10 }.  We have code blocks. Switch to HTML mode with the slash-in-angle-brackets icon and use code.../code around your code block.
  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    On second thought, I'm not sure if that makes the UI see the default. It makes the feature use 10 if teeth is undefined. That's not quite the same as putting 10 into the feature dialog.
  • john_f_carrjohn_f_carr Onshape Employees Posts: 74
    Try a Default annotation. You'll find them in std scattered around. For example, in boolean.fs annotation { "Name" : "Merge with all", "Default" : false } booleanDefinition.defaultScope is boolean; Default works for string, boolean, and enum. It doesn't work for number. I doubt there is a strong reason for it not working for number. Somebody needs to write the code. Maybe we'll get a feature request...
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    edited September 2015
    @john_f_carr The reason it does not work with quantities is because the defaults usually depend on the units, hence the valueBounds mechanism. isAnything (which is intended to let the feature user enter an arbitrary expression, though it's somewhat limited currently) is the one thing missing the default mechanism.

    In this case, the thing to do is to make a local copy of POSITIVE_COUNT_BOUNDS from valueBounds.fs and adjust the middle number (the default).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.