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 do I select individual entities from within a sketch?
thom_smith895
Member Posts: 3 ✭
Hi,
This is a very basic question, but I've struggled to find examples to move me past this problem.
I'd like to take two circles from a sketch and extrude one of them upwards, and one downwards.
The only example I have managed to find extrudes the whole sketch:
Can anyone help?
This is a very basic question, but I've struggled to find examples to move me past this problem.
I'd like to take two circles from a sketch and extrude one of them upwards, and one downwards.
The only example I have managed to find extrudes the whole sketch:
<div>opExtrude(context, id + "extrude2", {</div><div> "entities" : qSketchRegion(id + "sketch2", true),</div><div> "direction" : -connectorNormal,</div><div> "endBound" : BoundingType.BLIND,</div><div> "endDepth" : cDepth * millimeter</div><div> });</div>I need to query for "circle1" within "sketch2", and separately "circle2" within the same sketch.
Can anyone help?
0
Best Answer
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565You can query for individual sketch entities (that is, edges) with sketchEntityQuery().
Here's an example of that:
https://cad.onshape.com/documents/f4e19ad0a844db1cee04d131/w/f5ff2d97514cf25db4341773/e/a7e5fd093af8c6918096d9fc
However (and this often trips up FeatureScript authors), this only works for the sketch edges, not sketch regions. When you create a sketch with a collection of edges, Onshape creates a region for every bounded area (so, 3 regions for two overlapping circles) and there's no way to say after-the-fact that one region was "created" by one edge, since there's no mapping between those things in the general case.
This means the simplest way to query for separate regions is to just make two sketches and use qSketchRegion(). If you do need a single sketch (say, with regions that overlap), the second simplest thing to do is to query a single region with qContainsPoint().
Let us know if you have more questions!
5
Answers
Here's an example of that:
https://cad.onshape.com/documents/f4e19ad0a844db1cee04d131/w/f5ff2d97514cf25db4341773/e/a7e5fd093af8c6918096d9fc
However (and this often trips up FeatureScript authors), this only works for the sketch edges, not sketch regions. When you create a sketch with a collection of edges, Onshape creates a region for every bounded area (so, 3 regions for two overlapping circles) and there's no way to say after-the-fact that one region was "created" by one edge, since there's no mapping between those things in the general case.
This means the simplest way to query for separate regions is to just make two sketches and use qSketchRegion(). If you do need a single sketch (say, with regions that overlap), the second simplest thing to do is to query a single region with qContainsPoint().
Let us know if you have more questions!
Eduardo Magdalena C2i Change 2 improve ☑ ¿Por qué no organizamos una reunión online?
Partner de PTC - Onshape Averigua a quién conocemos en común
Many thanks. For simplicity I have created the features I need with separate sketches.
Kevin, thanks for the coded example of sketchEntityQuery(). An index of coded examples like yours (perhaps linked to from the Standard Library) would be a massive step forward in speeding up the learning this language.
Thanks again.