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.

Pre selection logic?

MichaelPascoeMichaelPascoe Member Posts: 1,710 PRO
edited March 2021 in FeatureScript
I'm having trouble understanding how to export a function. Can someone give me some pointers?

Here is what I'm trying to do:
If you have pre selected a plane and a vertex, then click the feature, the feature will detect that you are wanting to use the "Up to vertex" method. I'm trying export these definitions so that the interface will show you what has been selected. When I'm not trying to export the definitions, the code works great, but I wan't the user to see which method is selected.

A summary of my attempt:

annotation { "Feature Type Name" : "Section", "Auto Section Function" : "autoSection"}
export const section = defineFeature(function(context is Context, id is Id, definition is map)
        annotation { "Name" : "Plane or face", "Filter" : GeometryType.PLANE || EntityType.VERTEX, "MaxNumberOfPicks" : 2 }
        definition.rootPlane is Query;

        //Required to create a drop down menu.
        annotation { "Name" : "Section method" }
        definition.sectionMethod is sectionMethod;

        if (definition.sectionMethod == sectionMethod.UPTOVERTEX)
            annotation { "Name" : "Up to vertex", "Filter" : (EntityType.VERTEX), "MaxNumberOfPicks" : 1 }
            definition.limitEntity is Query;

export function autoSection(context is Context, id is Id, oldDefinition is map, definition is map) returns map
    if (oldDefinition != {}) // Only do anything on preselection
        return definition;

    //When I'm not trying to export, the following logic works great.
    if (size(evaluateQuery(context, definition.rootPlane)) == 2)

            const autoVertex = qEntityFilter(definition.rootPlane, EntityType.VERTEX);
            const autoPlaneOrFace = qSubtraction(definition.rootPlane, autoVertex);

            if (size(evaluateQuery(context, autoVertex)) == 1 && size(evaluateQuery(context, autoPlaneOrFace)) == 1)
                definition.sectionMethod = sectionMethod.UPTOVERTEX;
                definition.limitEntity = autoVertex;
                definition.rootPlane = autoPlaneOrFace;

    return definition;

Learn more about the Gospel of Christ  ( Here )

CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎

Best Answer


Sign In or Register to comment.