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.

Options

Appending or combining to qUnions

sean_connor714sean_connor714 Member Posts: 6
Is there a way to combine or append to a qUnion? In the code below, if "firstRow" is false, I'd like to add an additional subtract target to the boolean operation at the bottom. I've tried doing a qUnion of a qUnion and a qCreatedBy, but that doesn't seem to work either.

                var subtractTargets = qUnion([
                        qCreatedBy(id + i + "trussPoint", EntityType.BODY),
                        qCreatedBy(id + i + "slotForward", EntityType.BODY)
                ]);
                      
                if (firstRow == false)
                {
                    var previousPlane = plane(trussPoint * meter, -previousPlaneComponents.normal);
                    opExtrude(context, id + i + "slotBack", {
                        "entities" : definition.slot,
                        "direction" : evOwnerSketchPlane(context, {"entity" : definition.slot}).normal,
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : definition.bodyRadius
                    });
                
                    opTransform(context, id + i + "transformSlotBack", {
                        "bodies" : qUnion([
                            qCreatedBy(id + i + "slotBack", EntityType.BODY),
                        ]),
                        "transform" : transform(evOwnerSketchPlane(context, {"entity" : definition.slot}), previousPlane)
                    });
                    
                    subtractTargets = qUnion([subtractTargets, qCreatedBy(id + i + "slotBack", EntityType.BODY)]);
                }
                
                println(subtractTargets);
                opBoolean(context, id + i + "subtract", {
                    "tools" : qCreatedBy(id + i + "slotInterior", EntityType.BODY),
                    "targets" : subtractTargets,
                    "keepTools" : true,
                    "operationType" : BooleanOperationType.SUBTRACTION
                });
Thanks,

Answers

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,417
    edited December 2023
    That should work, but it's better to create an array of queries then qUnion the array at the end. Also, you don't need the qUnion in the opTransform.

    var subtractTargets = [
                            qCreatedBy(id + i + "trussPoint", EntityType.BODY),
                            qCreatedBy(id + i + "slotForward", EntityType.BODY)
                    ];
    
    subtractTargets = append(subtractTargets, qCreatedBy(id + i + "slotBack", EntityType.BODY));
    
    "targets" : qUnion(subtractTargets);
    Senior Director, Technical Services, EMEAI
  • Options
    _anton_anton Member, Onshape Employees Posts: 279
    edited December 2023
    Syntax looks right; I'd recommend using debug(context, myQuery) to make sure you're actually getting the expected queries. In what sense is it not working?

    (Protip: qUnion has overloads for 2, 3, and 4 queries, so you don't need to enclose them in an array in those cases.)
Sign In or Register to comment.