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.

Featurescript: Can't get qEdgeAdjacent to work?

jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
This basically my code with some bloat stripped out.  It creates an edge between two points and extrudes it into a face, then into a body (a door in this case).  I then want to extrude the face along the hinge so that I can form a union with the door frame (i.e. not just joined at an edge).
I'm getting there but not sure on qEdgeAdjacent and qVertexAdjacent (they keep giving me no results).

//create edge between two point
opFitSpline(context, id + "doorBase", {
     "points" : [ origin, otherside ]

// opExtrude edge ...
// opExtrude face ...

// turn doorBase into query
var doorBase is Query = qCreatedBy(id + "doorBase", EntityType.EDGE);
// find all faces that use doorBase
var facesFromEdge=qEdgeAdjacent(doorBase, EntityType.FACE);
// get doorOrigin from Vertex Query
var doorOrigin=qNthElement(definition.doorCorners, 0);
// find all faces that use door Origin
var facesFromVertex=qVertexAdjacent(doorOrigin, EntityType.FACE);
// to do ...
// find face which is in qOwnedByBody of the door and facesFromVertex but not in facesFromEdge 
//      this face is the hinge edge of the door required for extrusion.



  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 3,269
    Can't test your code since I'm not near my laptop but the first thing that jumps out at me is doorBase. This is a curve, so qEdgeAdjacent will resolve to nothing. You need the edges from your extrude. 
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
    edited September 2017
    See next comment instead ...
    Can I just clarify this function, it is easy to get confused as to how it works ...

    Does the following qEdgeAdjacent search the entire Part Studio for any FACES which were created using doorBase as an EDGE?
    If there is another edge in exactly the same position as doorBase, could that make a difference to the results?
    If I created another FACE using the doorBase edge and translated it (i.e. away from the original doorBase) would it still be returned in the results?
    facesFromEdge = qEdgeAdjacent( doorBase, EntityType.FACE );

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,019 ✭✭✭✭✭
    edited September 2017
    as documentation says: qEdgeAdjacent is a query for all entities of specified EntityType that share an edge with any entities that match the input query.
    so qEdgeAdjacent( doorBase, EntityType.FACE ) will return faces adjacent to the doorBase query, if you need edges adjucent to the doorBase face you need - qEdgeAdjacent( doorBase, EntityType.EDGE )
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
    I think what I get confused with is the 3 parts to the query ...

    qEdgeAdjacent( AB);

    Internally it will generate a list of all the edges in the entire Part Studio used by any entity in the list A.  This could be all the edges connected to single VERTEX in list A or all the EDGES of a BODY in list A, or both etc.
    It then returns a list of all the entities of TYPE B from the entire Parts Studio which use any of the edges it generated in the internal list.

    Is that right?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,019 ✭✭✭✭✭
    don't think it is right, if you need all the edges of the body you need qOwnedByBody(body, EntityType.EDGE), qEdgeAdjacent returns geometry adgacent to the seed query by the edge
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 494
    Probably a better name for qEdgeAdjacent() would be qSharesEdge(), and qVertexAdjacent() should be qSharesVertex().

    For example:
    ebug(context, qEdgeAdjacent(definition.edge1, EntityType.FACE));
    debug(context, qVertexAdjacent(definition.edge2, EntityType.FACE));d

    The name is meant to contrast edge-adjacency with vertex-adjacency.
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
    edited September 2017
    so qEdgeAdjacent( doorBase, EntityType.FACE ) will return faces adjacent to the doorBase query, if you need edges adjucent to the doorBase face you need - qEdgeAdjacent( doorBase, EntityType.EDGE )
    Sorry, missed this post.  That can't be the whole story because qVertexAdjacent would do exactly the same thing.
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭

    Yes, that is what I thought.

    This produces what you'd expect because you passed it an edge in defintion.edge1
    ebug(context, qEdgeAdjacent(definition.edge1, EntityType.FACE));

    But this uses the verticies of the edge from definition.edge2 
    debug(context, qVertexAdjacent(definition.edge2, EntityType.FACE));

    That is exactly what I thought, although I kept getting it backwards!  Thanks.
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
    edited September 2017
    I've found my problem - I think.

    I assumed that a face extruded from an edge shared that edge but it doesn't, it makes 4 new ones.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 494
    edited September 2017
    @jrs_spedley Correct, qEdgeAdjacent looks for topological adjacency (meaning the entities must be on the same body)

    To get the entities geometrically on a certain point, you can use qContainsPoint()
  • jrs_spedleyjrs_spedley Member Posts: 71 ✭✭
    edited September 2017
    ... and one more post for anyone searching in the future.

    Here is the finished code (the relevant part anyway)
    "newDoor" is a body - a door in this case - created from two Points: origin and otherside 
    The purpose of the function is to find the face of the door next to the hinge (origin) and is returned in faceByHinge

    var newDoor is Query = qCreatedBy(id + "newDoor", EntityType.BODY);

    //locate matching verticies for origin and otherside
    var doorOrigin;
    var doorOtherside;
    var vertexList = qVertexAdjacent(newDoor, EntityType.VERTEX);
    for (var vertex in evaluateQuery(context, vertexList)) {
        var vp=evVertexPoint(context, { "vertex" : vertex});
            if (tolerantEquals(vp,origin))
            else if (tolerantEquals(vp,otherside))
    //find edge between two matching verticies
    var doorEdge = qIntersection([qVertexAdjacent(doorOrigin, EntityType.EDGE), qVertexAdjacent(doorOtherside, EntityType.EDGE)]);

    //find surface to extrude - next to vertex but not edge
    var faceByHinge=qSubtraction(qVertexAdjacent(doorOrigin, EntityType.FACE), qEdgeAdjacent(doorEdge, EntityType.FACE));
Sign In or Register to comment.