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.

qCreatedBy doesn't work for boolean operation

forsaken_candyforsaken_candy Member Posts: 5 EDU

https://cad.onshape.com/documents/7fbb7c17072c33c64c6d093f/w/2fa9a3c83892a496d70c3208/e/000d61e242e94099cee63003

This document has a simple union of two bodies. According to the documentation for qCreatedBy:

If two entities are merged (as in a union of coincident faces), that entity is "created by" the creators of each merged entity, as well as the merging operation itself.

However this doesn't seem to work. I've tried both featurescript and UI, and both times the query returns zero bodies for the boolean operation.

Comments

  • Konst_ShKonst_Sh Member Posts: 86 PRO

    opBoolean is not considered to create bodies and faces, the identity of the body after opBoolean is inhereted from the first body passed to the tools. its one of the biggest gotchas of featurescript, since if multiple bodies are passed into tools and muliple disjoint resulting bodies are created you cannot rely on bodies queries through that operation

  • forsaken_candyforsaken_candy Member Posts: 5 EDU

    In that case the documentation should be fixed. I'm new to FS and I spent hours trying to figure out what was going on because I trusted it.

    The bodies I'm passing to the operation themselves come from queries, which do not guarantee a deterministic ordering. Does this mean the ID of the result is random every time?

  • Konst_ShKonst_Sh Member Posts: 86 PRO
    edited October 31

    you should look at the documentation for opBoolean itself:

    BooleanOperationType.UNION will merge any tool bodies that intersect or abut. All tool bodies have to be of the same type (solid or surface). When operating on surfaces, surfaces must have coincident or overlapping edges. When several bodies merge, the identity of the tool that appears earliest in the query is preserved (in particular, body color and body name are taken from it).

    so if you have something like that:

    const toolsQuery= …;

    const firstMergedBody = toolQuery→qNthElement(0);

    const mergedBodiesFromFaces = evaluateQuery(context, toolsQuery)→qUnion()→qOwnedByBody(EntityType.FACE)→qOwnerBody();

    opBoolean(context, id +"merge", {

    operationType:BooleanOperationType.UNION,

    tools: toolsQuery

    });

    then after boolean operation firstMergedBody query should resolve to first resulting body - if you are sure that this is the only body then you are good, if you can expect multiple merged bodies after boolean - you need some another approach -for example you can track bodies by their faces because surprisingly faces queries are more stable through boolean operation from my experience so mergedBodiesFromFaces should do the work as well.

    These are the generic approaches, not specific to any query types, because some types of queries can perform better than others in this circumstances and might not require that kind of trickery.

Sign In or Register to comment.