FS 355 Bug: isInteger with (unitless) bounds throwing ValueWithUnits error in Part Studio

malory_heliotis
malory_heliotis Member Posts: 2 ✭

Description

Issue:
I am developing a custom Sprocket Tool using FeatureScript 355. I am encountering a persistent runtime error in the Part Studio that prevents the feature from regenerating, despite the code passing the Feature Studio's static analysis.

Error Message in Part Studio:

Precondition of defineBounds failed (canBeBoundSpec(boundSpec))onshape/std/valueBounds.fs:388:9 (value.min is ValueWithUnits)

The Code:The error is triggered by the following unitless parameter definition:

export const MY_Teeth_Bounds = { (unitless) : [3, 18, 500] } as IntegerBoundSpec;


annotation { "Name" : "Number of Teeth" }
isInteger(definition.numTeeth, MY_Teeth_Bounds);

Observations:

  1. The Feature Studio notices show no errors; the function is recognized as "conforming" and the bounds are recognized as a "map" and a "range."
  2. The error value.min is ValueWithUnits suggests that the FS 355 runtime is incorrectly attempting to validate the unitless minimum value (3) against a physical length unit (likely millimeters or meters).
  3. I have attempted several workarounds, including:
    • Using isReal with RealBoundSpec.
    • Moving the map definition directly into the isInteger call (late-binding).
    • Using raw arrays [3, 18, 500] (which clears the Part Studio error but causes the Feature Studio to mark the function as "Nonconforming").

Environment:

  • FeatureScript Version: 355
  • Standard Library: onshape/std/geometry.fs version 355.0

Is this a known issue with the legacy valueBounds.fs in version 355, and is there a recommended way to define unitless integer ranges in this version that satisfies both the static analyzer and the Part Studio runtime?

Tagged:

Best Answer

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    Answer ✓

    Yes, so if 355 is your thing, it should be like this:

    const TEETH_BOUNDS = {
    "min" : 4,
    "max" : 250,
    (unitless) : [4, 25, 250]
    } as IntegerBoundSpec;
    Senior Director, Technical Services, EMEA

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image

    Any particular reason you are using a version of the standard library from May 16th 2016? Try it with the latest (2945) and report back.

    Senior Director, Technical Services, EMEA
  • jnewth
    jnewth Member, OS Professional Posts: 155 PRO

    Your MY_teeth_bounds or whatever is missing min and max fields. Using the onshape-std-library-mirror I was able to easily look at that legacy version and see:


    /** Typecheck for IntegerBoundSpec */export predicate canBeIntegerBoundSpec(value){ canBeBoundSpec(value); isInteger(value.min);

    isInteger(value.max);

    @size(value) == 3;

    value[unitless] is array;}

    so it's choking on the predicate (if i had to guess). Later versions don't have that min and max value.

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    Answer ✓

    Yes, so if 355 is your thing, it should be like this:

    const TEETH_BOUNDS = {
    "min" : 4,
    "max" : 250,
    (unitless) : [4, 25, 250]
    } as IntegerBoundSpec;
    Senior Director, Technical Services, EMEA