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.

Constrain queries being passed into functions

jacob_kingeryjacob_kingery Member Posts: 39 EDU
In a helper function (not a feature), is there a way to replicate the 'Filter' part of an annotation for a query parameter, like in the precondition of a feature?  I want to make sure that the query being passed in refers to geometry of a certain BodyType.

Best Answer

Answers

  • lanalana Onshape Employees Posts: 467
    Filter in annotation is strictly for UI use. You can  use qBodyType(inputQuery, bodyType) to filter the input
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 442
    qBodyType will filter by bodies.

    For the other filters allowed in the parameter filter, you can use qGeometryqEntityFilter, and qConstructionFilter.
  • jacob_kingeryjacob_kingery Member Posts: 39 EDU
    Right, but is there a way to require that the query being passed in refers to geometry of a certain BodyType?  Within the function, you could do something like this:
    export function myFunc(context is Context, q is Query)
    {
        if (size(evaluateQuery(context, qBodyType(q, BodyType.POINT))) == 0)
        {
            // throw error or something
        }
    }
    but this doesn't seem particularly elegant.  I guess it would be impossible for the code to know what the query would evaluate to without actually evaluating it, but it seems so clean when the UI just doesn't let you click on things that don't pass the filter.  It would be neat if functions could do something similar where they automatically throw an error if a query parameter doesn't pass a filter.
  • jacob_kingeryjacob_kingery Member Posts: 39 EDU
    Okay, I'll give that a try.  Thanks!
Sign In or Register to comment.