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.
Queried entity type evaluation
konstantin_shiriazdanov
Member Posts: 1,221 ✭✭✭✭✭
Now if your query supports several entity types (geometry types, body types) and you need to process them differently you have to create a number of constructions like
if (try silent evSomethig is Somenting) {}
else if (try silent evSomethingElse is SomethingElse) {}
...
and it seems to be not very elegant for the task of finding out what entity/geometry/body contains the query.
Am I missing something or there is a reason to ask for implementation of function like evQueryContetntType(query) which should return a map like {"entityType":entityType, "bodyType": bodyType, ''geometryType":geometryType} for a query refferensing single entity.
if (try silent evSomethig is Somenting) {}
else if (try silent evSomethingElse is SomethingElse) {}
...
and it seems to be not very elegant for the task of finding out what entity/geometry/body contains the query.
Am I missing something or there is a reason to ask for implementation of function like evQueryContetntType(query) which should return a map like {"entityType":entityType, "bodyType": bodyType, ''geometryType":geometryType} for a query refferensing single entity.
2
Comments
-
Generally speaking we prefer to use queries rather than evaluations to solve filtering problems. They are more efficient, they're lazily run, they don't give the user data which can go out of date, and (hopefully) they involve writing less FeatureScript.
For your case, can e.g. qGeometry() be used to do the job? If not, why not? We can certainly look into adding more queries like a qGeometry with multiple types, or a qHasAxis or qHasDirection to correspond with evAxis and evDirection.
For something like evSurfaceDefinition, I'd say your construction actually is good, canonical FeatureScript. One alternative is to wrap each in e.g. if(evaluateQuery(qGeometry(...)) != [] ). I think you'll find that the performance is about the same (since the ev functions themselves will fail early).
0 -
For example in my Measure distance extended FS for angle evaluation a have to extract direction vector from entities that have axis and normal vector for planes, and i have to wrap it into if-else tests. For two entities I had to write four tests - this doesn't look like reducing amount of code. And i can remember several more cases when i would like explicitly know queried entity type instead of bulky tests, at least so is my thoughts.
1 -
The request makes sense to me. The modifications I would make to the proposal are: not restrict it to one entity, but return an array of maps, and also include the transient query in each map. This may also be a good way of returning other cheap-to-get per-entity info, such as whether it is modifiable, construction geometry, or belongs to a sketch.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc2
-
@ilya_baran, thank you for your attention, should I make this an improvement request?
0 -
Yes, please. That'll ensure that you get a notification email when one of us implements it.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
@konstantin_shiriazdanov
Go check out 'extractDirection(...)' in 'topoloyUtils.fs', as well as 'QueryFilterCompund.ALLOWS_DIRECTION' in 'query.fs'. It doesn't solve the wider problem you are asking about, but it is a built-in way of doing what you want in Measure Distance.Jake Rosenfeld - Modeling Team1 -
thanks @Jake_Rosenfeld, it would somehow simplify the code
0 -
I think I have a similar situation. I'm trying to get a direction vector from a face or edge. The direction will be determined differently depending on the entity chosen. Is @Jake_Rosenfeld's suggestion my best option? Should I use qGeometry() and check if the result is an empty array?konstantin_shiriazdanov said:For example in my Measure distance extended FS for angle evaluation a have to extract direction vector from entities that have axis and normal vector for planes, and i have to wrap it into if-else tests. For two entities I had to write four tests - this doesn't look like reducing amount of code. And i can remember several more cases when i would like explicitly know queried entity type instead of bulky tests, at least so is my thoughts.0 -
Has this been implemented? If not, where is the correct place to vote?
Found it:
https://forum.onshape.com/discussion/7074/feature-script-queried-entity-type-evaluation
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________1 -
@Kyler_Walker If you're seeking a direction, you can use QueryFilterCompound.ALLOWS_DIRECTION to enable direction selection (or a subset of direction entities, like GeometryType.PLANE || EntityType.EDGE), and extractDirection to cleanly convert that direction into a vector. extractDirection will automatically choose the direction correctly based on the type of selection; the face normal if it's a face, the edge direction if it's an edge, the cylinder axis if it's an axis, etc.
Software Developer at Epic Systems
FRC Design Mentor - Team 1306 BadgerBots2 -
Thanks. That does exactly what I want.Alex_Kempen said:@Kyler_Walker If you're seeking a direction, you can use QueryFilterCompound.ALLOWS_DIRECTION to enable direction selection (or a subset of direction entities, like GeometryType.PLANE || EntityType.EDGE), and extractDirection to cleanly convert that direction into a vector. extractDirection will automatically choose the direction correctly based on the type of selection; the face normal if it's a face, the edge direction if it's an edge, the cylinder axis if it's an axis, etc.0






