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 can I efficiently find every body that has a coplanar face to an input?
EvanReese
Member, Mentor Posts: 2,135 ✭✭✭✭✭
I have a query of planar face(s) as inputs, and would like to query every body that has any face that is co-planar with any of the inputs (selectedFaces). I got it working like this, but I'm getting really bad re-build times. I'm sure there's got to be a much faster way that my 5pm brain isn't seeing. Anybody have any tips or examples for me?
var selections = qNothing(); var allPlanarFaces = evaluateQuery(context, qSketchFilter(qConstructionFilter(qGeometry(qEverything(EntityType.FACE), GeometryType.PLANE), ConstructionObject.NO), SketchObject.NO)); var selectedFaces = evaluateQuery(context, definition.faces); var selectedBodies = qNothing(); for (var face in selectedFaces) { var plane = evPlane(context, { "face" : face }); for (var referenceFace in allPlanarFaces) { var referencePlane = evPlane(context, { "face" : referenceFace }); var isCoplanar = coplanarPlanes(plane, referencePlane); if (isCoplanar) { selections = qUnion([selections, qOwnerBody(referenceFace)]); } } }
Evan Reese
0
Best Answers
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646Hey Evan!
I suspect the fastest you can do it is something like:// -> notation is newly released. // qGeometry(qEverything(EntityType.FACE), GeometryType.PLANE) can now be written more simply as as qEverything(EntityType.FACE)->qGeometry(GeometryType.PLANE) // The arrow simply means "insert the thing before the arrow as the first argument to the thing after the arrow" const allPlanarFaces = qEverything(EntityType.FACE)->qGeometry(GeometryType.PLANE)->qConstructionFilter(ConstructionObject.NO)->qSketchFilter(SketchObject.NO); const resultArr = []; for (var face in evaluateQuery(context, definition.faces)) { const plane = evPlane(... face ...); // filter down to parallel planes, and then filter further to coincident, resulting in coplanar const coplanar = qParallelPlanes(allPlanarFaces, plane.normal)->qCoincidesWithPlane(plane)); resultArr = append(result, coplanar); // Appending to an array is better than qUnion with a master query<br>} const result = qUnion(resultArr); debug(context, result);
** formatting is getting messed up. -> should be "->"Jake Rosenfeld - Modeling Team0 -
ilya_baran Onshape Employees, Developers, HDM Posts: 1,212Haven't tested it, but qCoincidesWithPlane would be key here I think. Something like:
qEverything(EntityType.FACE)->qCoincidesWithPlane(myPlane)->qOwnerBody()
looking at our internal implementations, it's possible that qEverything(EntityType.FACE)->qParallelPlanes(myPlane)->qCoincidesWithPlane(myPlane)->qOwnerBody() would actually be faster -- worth testing.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
Answers
I suspect the fastest you can do it is something like:
** formatting is getting messed up. -> should be "->"
qEverything(EntityType.FACE)->qCoincidesWithPlane(myPlane)->qOwnerBody()
looking at our internal implementations, it's possible that qEverything(EntityType.FACE)->qParallelPlanes(myPlane)->qCoincidesWithPlane(myPlane)->qOwnerBody() would actually be faster -- worth testing.
I might be taking this script in a whole different direction, but If I come back to this, I'll implement these changes. I'll mark it "answered" even though I've not tested it, because I'm pretty sure you're going to be right.