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 "Measure Angle" Feature Script Code001

warren_pegleywarren_pegley Member Posts: 14
// This is the first time I've touched this code - so a point in the right direction would be helpful, I think this script would be a helpful asset also so if there joy in punching out new features - please do.

FeatureScript 1271;
import(path : "onshape/std/geometry.fs", version : "1271.0");

/** Measure the Angle between two sets of entities and set the result to a variable */
annotation { "Feature Type Name" : "Measure Angle", "Feature Name Template" : "###name = #value", "UIHint" : "NO_PREVIEW_PROVIDED" }
export const measureAngle = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Name", "Default" : "Angle" }
        definition.name is string;

        annotation { "Name" : "First entities", "Filter" : EntityType.FACE || EntityType.EDGE || EntityType.VERTEX || EntityType.BODY }
        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 angleResult is AngleResult = evAngle(context, {
                    "side0" : definition.first,
                    "side1" : definition.second,
                    "maximum" : definition.maximum
                });

        const p0 = angleBetween(vector1, vector2)Result.sides[0].point;
        const p1 = angleBetween(vector1, vector2)Result.sides[1].point;
        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);
        }

        setFeatureComputedParameter(context, id, {
                "name" : "value",
                "value" : angleBetween(vector1, vector2)Result.angle
        });
        setVariable(context, definition.name, angleResult.angle);
    });

Comments

Sign In or Register to comment.