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.

Writing a measured value to a variable in the model tree and keeping it updated.

Chris_LoughnaneChris_Loughnane Member Posts: 4 PRO
Essentially I'm trying to recreate a 'sensor' or User-Defined Measurement. In the simplest case I have an arc, would like to evaluate it's length, then store that number in a variable so that I can reference it later in my model tree. 

I'm just jumping into featurescript so it's not immediately obvious to me how to do this, if I can do it, or if it's already been done.


  • abefeldmanabefeldman Member Posts: 166
    edited July 2017
  • Chris_LoughnaneChris_Loughnane Member Posts: 4 PRO
    Using the suggestions above made a slight adjustment in order to measure length

    annotation { "Feature Type Name" : "Measure Length", "Feature Name Template" : "###name = #value", "UIHint" : "NO_PREVIEW_PROVIDED" }    export const measureLength = defineFeature(function(context is Context, id is Id, definition is map)    precondition    {        annotation { "Name" : "Name", "Default" : "length" }        definition.name is string;
            annotation { "Name" : "First entities", "Filter" : EntityType.EDGE }        definition.first is Query;
            // annotation { "Name" : "Second entities", "Filter" : EntityType.FACE || EntityType.EDGE || EntityType.VERTEX || EntityType.BODY }        // definition.second is Query;
            // annotation { "Name" : "Maximum" }        // definition.maximum is boolean;    }    {        if (!match(definition.name, '[a-zA-Z_][a-zA-Z_0-9]*').hasMatch)            throw regenError(ErrorStringEnum.VARIABLE_NAME_INVALID);                    const lengthResult is ValueWithUnits = evLength(context, {                "entities" : definition.first        });
            // if (!tolerantEquals(p0, p1))        // {        //     debug(context, line(p0, p1 - p0));        //     debug(context, line(p1, p0 - p1));        // }        // else // If it's the same point, just draw the point        // {        //     debug(context, p0);        // }
            setVariable(context, definition.name, lengthResult);
            setFeatureComputedParameter(context, id, { "name" : "value", "value" : lengthResult });    });

Sign In or Register to comment.