Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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_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.
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215You could make a precondition for this function and put there: evaluateQuery(context, qBodyType(q, BodyType.POINT)) == []
But the behavior we typically have in our standard library is to accept arbitrary queries, filter out everything we don't need, and then possibly complain if the query is empty.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
For the other filters allowed in the parameter filter, you can use qGeometry, qEntityFilter, and qConstructionFilter.
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.
But the behavior we typically have in our standard library is to accept arbitrary queries, filter out everything we don't need, and then possibly complain if the query is empty.