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 to use qAdjacent with Sketch-entities?

timo_schmidtimo_schmid Member Posts: 36 EDU
Hi everyone,
I'm trying to select all the adjacent vertices to a sketch-Face, that are also part of a selected set of points. See following code:
&nbsp;&nbsp;&nbsp; precondition<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; annotation { "Name" : "area", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; definition.area is Query;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; annotation { "Name" : "edge", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; definition.vertex is Query;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var vertices = qAdjacent(definition.area, AdjacencyType.VERTEX, EntityType.VERTEX);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var evvertices = evaluateQuery(context, vertices);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var match = qIntersection([vertices , definition.vertex]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var evmatch = evaluateQuery(context, match);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(evvertices);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(evmatch);<br>&nbsp;&nbsp;&nbsp; });
When I select a Face of a body and one of the adjacent vertices, the Intersection query works and I get 1 match.
When doing the same with a sketch-face and one of its vertices, it doesn't work.

Does anyone know how this can be achieved for a sketch entity?
Thank you,
Timo



Best Answer

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited July 2020 Answer ✓
    If you debug everything created by a sketch, you'll see that a sketch operation usually creates two things:
    1) Wire bodies for every sketch edge
    2) Surface bodies with faces for each enclosed sketch region

    When you're select into definition.area, you click the face of a sketch surface body. When you're selecting into definition.vertex, selection precedence makes you most likely to choose the vertices owned by the wire bodies.

    Since the two are on different bodies, qAdjacent doesn't consider them to be topologically adjacent. So this problem is more general than sketches: It would happen any time definition.area and definition.vertex are on different bodies.

    To solve this, you can get the 3D position of the selected point using evVertexPoint(...). From there, (assuming you still need this query) you can query for qContainsPoint(qAdjacent(definition.area, AdjacencyType.VERTEX, EntityType.VERTEX), evaluatedPoint)

Answers

  • timo_schmidtimo_schmid Member Posts: 36 EDU
    Somehow the code is not displayed, so here it is:
    <br>
    &nbsp;&nbsp;&nbsp; precondition<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; annotation { "Name" : "area", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; definition.area is Query;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; annotation { "Name" : "edge", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; definition.vertex is Query;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var vertices = qAdjacent(definition.area, AdjacencyType.VERTEX, EntityType.VERTEX);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var evvertices = evaluateQuery(context, vertices);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var match = qIntersection([vertices , definition.vertex]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var evmatch = evaluateQuery(context, match);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(evvertices);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(evmatch);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; });<br>

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited July 2020 Answer ✓
    If you debug everything created by a sketch, you'll see that a sketch operation usually creates two things:
    1) Wire bodies for every sketch edge
    2) Surface bodies with faces for each enclosed sketch region

    When you're select into definition.area, you click the face of a sketch surface body. When you're selecting into definition.vertex, selection precedence makes you most likely to choose the vertices owned by the wire bodies.

    Since the two are on different bodies, qAdjacent doesn't consider them to be topologically adjacent. So this problem is more general than sketches: It would happen any time definition.area and definition.vertex are on different bodies.

    To solve this, you can get the 3D position of the selected point using evVertexPoint(...). From there, (assuming you still need this query) you can query for qContainsPoint(qAdjacent(definition.area, AdjacencyType.VERTEX, EntityType.VERTEX), evaluatedPoint)
  • timo_schmidtimo_schmid Member Posts: 36 EDU
    Thanks @kevin_o_toole_1 for the explanation!
    Just one follow-up question: In my actual application I have more than just one point selected, and want to match all the points within this set, that are also adjacent to the Face.
    Do you know if there is a way to efficiently achieve this (without summing over all individual qContainsPoint-queries)?
    Thank you,
    Timo


  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    If you need queries for those points, a qUnion of qContainsPoint's seems to be the most reasonable way.
Sign In or Register to comment.