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.

Difficulty with defining a volume parameter

Matthew_WilsonMatthew_Wilson Member, csevp Posts: 4 PRO
I'm writing a feature that takes a volume measurement from the user.  I'm running into trouble with the isVolume predicate:
FeatureScript 1821;
import(path : "onshape/std/geometry.fs", version : "1821.0");

annotation { "Feature Type Name" : "My Feature" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        // Define the parameters of the feature type
        annotation { "Name" : "My Volume" }
        isVolume(definition.myVolume, VOLUME_BOUNDS);
        
    }
    {
        // Define the function's action
    });

The volume definition throws the warning: "Expected parameter id to be defined as a field on val"  I have zero idea what that means.  I don't think that I'm using it wrong, it's documented here: https://cad.onshape.com/FsDoc/library.html#isVolume--VolumeBoundSpec  This is just the same as a Length definition, what am I missing?

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    There is currently no "volume parameter" UI for that syntax to map onto. If we supported it, I'd bet our syntax would match your snippet, but we don't support it yet.

    If you want to input a volume, two possible workarounds are:
    1. Input a plain real number, interpret it in your code as e.g. in^3
    2. Input an isAnything() parameter, have the user manually type the value and units e.g. 3 in^3 into that input
  • Jacob_CorderJacob_Corder Member Posts: 126 PRO
    You could also have an enum for volume units that you want to use. input a number and another input, its units. then convert it in your code to a ValueWithUnits.
     
  • Matthew_WilsonMatthew_Wilson Member, csevp Posts: 4 PRO
    Thanks Kevin and Jacob!  I did end up using isReal and converting it to mm^3.  It's just a quick and dirty FS for now so that works out.  I like the isAnything, I could then at least validate the input and allow other units.

    I was confused because the docs seem to indicate that you can use isVolume in this way.  Maybe we can get an improvement request to add a volume parameter to the UI? ;-)
Sign In or Register to comment.