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.

variable default value with MIN and MAX for length input

How can I specify a default value for a length input and also specify a minimum and maximum value? The values are again dependent on a previously made selection.
I found the defineLengthTolerance command in hole.fs, but I can't reproduce it.

Tagged:

Comments

  • _anton_anton Member, Onshape Employees Posts: 413
    A length parameter is specified like

            annotation { "Name" : "My Length" }
            isLength(definition.myLength, LENGTH_BOUNDS);

    That LENGTH_BOUNDS is just a map, and you can write your own. For example:

            annotation { "Name" : "My Length" }
            isLength(definition.myLength, { (centimeter): [0, 1, 500] } as LengthBoundSpec);
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited February 2023
    A good autocomplete for this is "Length parameter (custom bounds)" so you can fill in the following:

        annotation { "Name" : "My Length" }
            isLength(definition.myLength, { (inch) : [ -10000, /* min (inclusive) */
                                                       1.0,    /* default */
                                                       10000   /* max (inclusive) */ ] } as LengthBoundSpec );

    One thing to keep in mind is that your defaults can be different in workspaces using different units, which you can do by adding more items to that map. This helps avoid issues where you see defaults with strange decimal values. For example, the default LENGTH_BOUNDS is defined as:

    export const LENGTH_BOUNDS =
    {
        (meter)      : [-500, 0.025, 500],
        (centimeter) : 2.5,
        (millimeter) : 25.0,
        (inch)       : 1.0,
        (foot)       : 0.1,
        (yard)       : 0.025
    } as LengthBoundSpec;

  • georg_von_vietinghoffgeorg_von_vietinghoff Member Posts: 9 ✭✭
    ok, that's the first step in the right direction! Thank you very much for that!
    If now the values could stand as variable (default, min, max) in the tolerance definition, then I would be again a step further.
  • georg_von_vietinghoffgeorg_von_vietinghoff Member Posts: 9 ✭✭
    something like this

Sign In or Register to comment.