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.
How to create a new type of Query?
dave_cowden
Member, Developers Posts: 475 ✭✭✭
I'd like to create a new type of query that i'm used to using in cadquery:
ability to select faces that line parallel to, and most 'positive' with respect to, a specified direction.
As an example, suppose i extrude a circle with an extrusion axis in the positive "Z" direction. the resulting object has 3 faces.
What i want to do is select the 'top most' face: the one that is furthest in the extrusion ( in this case, z) direction
in cadquery, you would do this with a query like:
There seems to be three ways to do this in FS, but they are all very inconvenient.
(1) i could use qIntersectsPlane. but it is a pain to create an intersecting plane just to run a query
(2) use qContainsPoint. again, it is a pain to manually find a point that should lie on the surface. Plus in testing, when i tried, it didnt select anything: this could be a precision issue.
(3) use qNthElement . this works reliably, but it seems like a gamble to assume that the faces will be generated in the right order every time. It feels like it would always be indeterministic to use this selector.
What i want to make is something like qFarthestAlong( direction, qCreatedBy ( context, id, EntityType.FACE ))
I've found the makeQuery function, but its not obvious how to use it. I think i know how to implement what i want to do using evTangentPlane, if i could get some pointers on what the right way to produce queries that decorate other queries is. I know i could use evaluateQuery to get the result of the query i'm composing, but then how do i return a query that executes a filter?
Thanks as always for the help
ability to select faces that line parallel to, and most 'positive' with respect to, a specified direction.
As an example, suppose i extrude a circle with an extrusion axis in the positive "Z" direction. the resulting object has 3 faces.
What i want to do is select the 'top most' face: the one that is furthest in the extrusion ( in this case, z) direction
in cadquery, you would do this with a query like:
w = Workplane("XY").circle(0.4).extrude(1.0).faces(">Z")
There seems to be three ways to do this in FS, but they are all very inconvenient.
(1) i could use qIntersectsPlane. but it is a pain to create an intersecting plane just to run a query
(2) use qContainsPoint. again, it is a pain to manually find a point that should lie on the surface. Plus in testing, when i tried, it didnt select anything: this could be a precision issue.
(3) use qNthElement . this works reliably, but it seems like a gamble to assume that the faces will be generated in the right order every time. It feels like it would always be indeterministic to use this selector.
What i want to make is something like qFarthestAlong( direction, qCreatedBy ( context, id, EntityType.FACE ))
I've found the makeQuery function, but its not obvious how to use it. I think i know how to implement what i want to do using evTangentPlane, if i could get some pointers on what the right way to produce queries that decorate other queries is. I know i could use evaluateQuery to get the result of the query i'm composing, but then how do i return a query that executes a filter?
Thanks as always for the help
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,211The part studios at 275 are an artifact of an upgrade process that didn't go quite right this cycle. The bug is fixed for the next deployment. I have manually upgraded Dave's part studios.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
Using just the geometry (and not the history) can often still be useful, though. After all, what if the geometry I'm querying is an import?
So, let's make a function that gets an entity like you're proposing. To do this, we'll be using evDistance, which may be more powerful than you'd first realize.
But first, let's first make one minor adjustment: To make the choice of entity unambiguous between the cap faces and side faces (both of which touch the farthest plane), let's replace "farthest along this vector" with "closest to the point farthest along this line".
A function which does that can be constructed as follows:
For a result like this:
The closestToEndOfLine function returns a Query, so to whomever calls it, it will behave a lot like any of the other query functions. However, there are some key differences:
1. You have to pass in a context.
2. A subtle consequence of #1: You should only use this call function immediately before using its result. Onshape queries specify what they want independently of the context, so the same query can be used after the context has changed, yielding different results that still correctly match the query in the new context. The query returned by closestToEndOfLine, in contrast, needs a context just to build the correct query. This means calling closestToEndOfLine() in a context, then using it after changing that context, won't necessarily be accurate. (Trivial example: You could have built a new entity further along the line in the meantime).
3. The function likely has slower performance than an Onshape native query would. This won't be relevant unless you're using said function quite a lot.
Making utility functions like this is definitely encouraged, so long as you're aware of these differences.
I agree that having a query-only version of something would be nice. For the most part, we're likely not going to be putting major emphasis on expanding the query library with things like this until (possibly) this summer.
This one looks useful enough though, that we may make an exception.
I"m trying to use some code like you pasted above:
But to use that function, evidently i needed to upgrade my FeatureScript file to version 293.
But then, i cannot use the feature in part studio, because part studio defaults to version 275-- and I get this error:
"Cannot import a module with FeatureScript version: 293 from module with older version 275"
What's the trick to get a part studio to be a later FS version so you can use later modules?
I'm off and running again!