Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_smith895thom_smith895 Member Posts: 3
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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "entities" : qSketchRegion(id + "sketch2", true),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "direction" : -connectorNormal,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endBound" : BoundingType.BLIND,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endDepth" : cDepth * millimeter</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</div>
I need to query for "circle1" within "sketch2", and separately "circle2" within the same sketch.  

Can anyone help?

Best Answer


  • emagdalenaC2iemagdalenaC2i Member, Developers Posts: 648 ✭✭✭✭✭
    Why you don't create a sketch for each circle?

    Un saludo,

    Eduardo Magdalena                           C2i Change 2 improve                           ☑ ¿Por qué no organizamos una reunión online?   
                                                                 Consulting Partner de Onshape                                      Averigua a quién conocemos en común

                                         Live Chat at Discord about Onshape & FeatureScript

    Consulta mis cursos de Onshape en Español:
  • thom_smith895thom_smith895 Member Posts: 3
    Kevin, emagdalena,

    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.
  • EricZEricZ Member Posts: 1 PRO
    You can query for individual sketch entities (that is, edges) with sketchEntityQuery().

    Here's an example of that:

    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!

    however qContainsPoint() has to use a vector in 3D point, but on the 2D sketch is there some other simple way? 
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 3,426
    You can use toWorld() to convert a point location on your sketch to a 3D point. 
Sign In or Register to comment.