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 values not working.

adamohernadamohern Member, OS Professional Posts: 216 PRO
I'm filling in the default values in my feature. They look fine in the code (no error flags), but they seem to be ignored when instantiating the feature. Is there a trick to getting defaults to work properly?

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited April 2016
    That defaults map controls the default values when your feature function is called from another FeatureScript feature, or when old features that lack a new parameter regenerate.

    This does NOT control the user default value when creating this feature for the first time. That's controlled separately via an annotation.

    To change the user-visible default for booleans, enums, and strings, use the "Default" annotation:
    annotation { "Name" : "Hollow", "Default" : false }
    definition.isHollow is boolean;

    To change the user-visible default for a length, angle, or number, you'll need to specify it inside a value bound, which you can create as a constant before your feature:
    const MY_BOUNDS =
    {
        "min"    : -TOLERANCE.zeroAngle * radian,
        "max"    : (2 * PI + TOLERANCE.zeroAngle) * radian,
        (degree) : [0, 45, 360],
        (radian) : 1
    } as AngleBoundSpec;
    ...
        isAngle(definition.myAngle, MY_BOUNDS);
    ...

    Note that the default values are different based off a users' default units. Check out the valueBounds module for some examples of bounds used in Onshape features.

    I agree the difference is confusing now, but fortunately this stuff will be documented better in 1.45.

  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    Oh wow, I was way off! Many thanks for the quick response. I'm sure I'll work through it.
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    I'm working with US stock, so my default edge round is 1/4" regardless of the user's display unit. I'm currently brute-forcing that using:

    export const EDGE_ROUND_BOUNDS =
    {
        "min"        : -TOLERANCE.zeroLength * meter,
        "max"        : 500 * meter,
        (meter)      : [1e-5, 0.00635, 500],
        (centimeter) : 0.635,
        (millimeter) : 6.35,
        (inch)       : .25,
        (foot)       : 0.02083333,
        (yard)       : 0.006944444
    } as LengthBoundSpec;

    This is obviously redundant. Is there a cleaner way to do this if all I want is a default value regardless of display unit?
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    For all of Onshape's features, we use round numbers in all units (it's less visually noisy) so the need for a simpler way never came up. But you're bringing up a good point here: a standard size is definitely a legitimate use case.

    Unfortunately, the precondition analysis expects the BOUNDS that you provide to be declared as a map literal, so you can't even make a simple function like lengthBoundsWithExactDefault(1/4 * inch) which would return the right thing.

    For now the syntax you're using is the best thing available, but yeah, it's not great. We'll think about making the precondition analysis smarter, and adding lengthBoundsWithExactDefault to the Standard Library.

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    An alternative is to only specify inches in the bound (you'd need the min and max in inches too) -- then the default would be "0.25 in" regardless of the document units.  Not obvious to me if it's more or less desirable than a specification of the same length in document units -- since the design intent for that value is really inches.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    edited April 2016
    You mean like this?
    export const EDGE_ROUND_BOUNDS =
    {
        "min"        : -TOLERANCE.zeroLength * inch,
        "max"        : 50000 * inch,
        (inch)      : [1e-50, 0.25, 50000]
    } as LengthBoundSpec;
  • adamohernadamohern Member, OS Professional Posts: 216 PRO
    We'll think about making the precondition analysis smarter, and adding lengthBoundsWithExactDefault to the Standard Library.
    I would recommend reconsidering the requirement for a bounds object, and allow something simpler, like the "Default" parameter in a boolean query. Bounds would, of course, be the more powerful method for advanced users, but I think a typical user would prefer a more straightforward way of setting a default value without bothering with the rest of it.
Sign In or Register to comment.