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.

Queries, queries and more queries ...

ron_morelandron_moreland Member Posts: 79 ✭✭
edited January 2018 in Community Support
Here is a simple FS:

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

annotation { "Feature Type Name" : "FS Test" }
export const fstest = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Plane", "Filter" : GeometryType.PLANE || EntityType.FACE , "MaxNumberOfPicks" : 1 }
        definition.tPlane is Query;
    }

    {
        const thePlane = evaluateQuery(context, definition.tPlane);

        debug(context, "DBG1 "~ thePlane );
        debug(context, "DBG2 "~ thePlane[0] );
        if ( canBePlane(thePlane[0]) )
        {
            debug(context, "Can be a Plane");
        }
        else
        {
            debug(context, "Not a PLANE");
        }
    }

    );


and here is the debug output:

debug: DBG1 [ Query : { "queryType" : QueryType : "TRANSIENT" , "transientId" : TransientId : BuiltIn: 7 } ] debug: DBG2 Query : { "queryType" : QueryType : "TRANSIENT" , "transientId" : TransientId : BuiltIn: 7 } debug: Not a PLANE Result: Regeneration complete

I read the Docs carefully, evaluteQuery() returns an array of queries. So how do I get the things?

Best Answer

Answers

  • ron_morelandron_moreland Member Posts: 79 ✭✭
    Thank you for the reply. In your response:

    if (foo is Plane)

    What is "foo"? Is it an entity?  Geometry? A query? A query to an entity that might be a Plane. If you have to evaluate a query with the proper ev* to get the actual entity, how can this work if you don't know what ev* to use?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited January 2018
    currently the direct way of evaluation of queries doesn't exist in FS, so we have to use tests like above, you apply ev function to the query and check if the result is of type you expect - then you may do some type-specific actions with it. since there are no case/switch operator if/else tests is the best we can do.
    the other solution can be using try silent {} for example:
    try silent
    {
    p = evPlane( query)
    //if evPlane doesn't fails you may perform actions with p
    }
    try silent
    {
    l = evLine(query)
    //if query evaluates to line evPlane failed and you are switched to this branch of code
    }
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    @ron_moreland
    In my example "foo" can be any FeatureScript value.
    I would not think about it as "getting at the real entity" -- the "real" entity exists deep within the context and is impossible to "get at".  The way FS works is you describe the set of entities you want to ask about using a query and then get data about these entities using ev functions -- the Plane returned by evPlane is not tied to the planar face at all -- it's just the coordinates of that plane.

    One of the reasons for this design is that operations can change the "real" underlying entities in rather unpredictable ways, e.g., splitting and merging them, changing types, etc. and trying to hold on to a specific entity would not work well.

    Deciding which ev to use depends on what you're trying to achieve.  If you want to know know the type of face, for instance, evSurfaceDefinition will tell you.  evPlane is just simpler if you happen to know that you are referencing a plane (which happens frequently -- either because of you specified a selection filter in you feature's query parameter or because you just created one or because your query is a qGeometry).  Most ev functions, like evDistance or evFaceTangentPlane do not require you to know the type of geometry you're dealing with.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • ron_morelandron_moreland Member Posts: 79 ✭✭
    Thanks for the patient replies. My brain is stiff, gotta stretch the synapses.
Sign In or Register to comment.