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

Query for entities to boolean

ben_partouchben_partouch Member Posts: 95 PRO
Hi,
I'm trying to boolean subtract bodies created with oppattern inside a for loop. Not sure what I should do...

Thank you!

doc:
https://cad.onshape.com/documents/ef3ba98102efc6b4e4c71194/w/50cf1b58a05a4b7c535589fd/e/8c530af3038d5e69dbf7c755

for (var i = -1; i < definition.numberOfHoles - 1; i += 1)
        {
            const computedTransforms1 = transform((vector(0 * centimeter, 0 * centimeter, definition.holeSpacing)) * (i + 1));

            opPattern(context, id + ("patternB" ~ i), {
                        "entities" : qCreatedBy(id + "extrude1", EntityType.FACE),
                        "transforms" : [computedTransforms1],
                        "instanceNames" : ["Holes"]
                    });

            // opBoolean(context, id + "boolean2", {
            //             "tools" : qCreatedBy(id + ("patternB" ~ i), EntityType.BODY),
            //             "targets" : definition.panels,
            //             "operationType" : BooleanOperationType.SUBTRACTION
            //         });

        }
Tagged:

Comments

  • Options
    Jacob_CorderJacob_Corder Member Posts: 126 PRO
    Change your pattern to EntityType.BODY not EntityType.FACE

    opPattern(context, id + ("patternB" ~ i), {
                            "entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
                            "transforms" : [computedTransforms1],
                            "instanceNames" : ["Holes"]
                        });
  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    Thanks @Jacob_Corder.

    Looks like it can stay FACE but my id was wrong. Now- opBoolean(context, id + ("boolean2" ~ i).
    Seems to work:)
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,396
    For speed, build an array of transforms and names in the for loop then do opPattern and opBoolean once. Our servers will thank you. 
    Senior Director, Technical Services, EMEAI
  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    Thanks @NeilCooke
    I would love to take you advice but my capabilities in FS are so amature and limited that I have no idea how to do what you suggested LOL.
    My code is so inefficient. Would love to learn how to get better at this!



  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 PRO
    edited May 2023
    He means something like this. I've not tested this code, but the idea is there if not the functionality.
    //for loop for drilled holes
            var computedTransforms1 = []; // make an empty array to later store transforms
            var instanceNames = []; // make an empty array to later store instance names<br>
            for (var i = -1; i < definition.numberOfHoles - 1; i += 1)
            {
                const computedTransform = transform((vector(0 * centimeter, 0 * centimeter, definition.holeSpacing)) * (i + 1));
                computedTransforms1 = append(computedTransforms1, computedTransform); // add the new transform to the array
                instanceNames = append(instanceNames, "hole"~toString(i)); // add the new instance name to the array<br>
            }
    // no more need to add + i to the Id's here since you only call the functions once.
                opPattern(context, id + "patternB", {
                            "entities" : qCreatedBy(id + "extrude1", EntityType.FACE),
                            "transforms" : computedTransforms1,
                            "instanceNames" : ["Holes"]
                        });
    
                opBoolean(context, id + "boolean2", {
                            "tools" : qCreatedBy(id + "patternB", EntityType.BODY),
                            "targets" : definition.panels,
                            "operationType" : BooleanOperationType.SUBTRACTION
                        });

    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    I'll give it a shot! Thanks guys.

  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    Couldn't make it to work. 
    Thanks for looking into it:)
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,396
    Couldn't make it to work. 
    Thanks for looking into it:)
    Which bit is failing?
    Senior Director, Technical Services, EMEAI
  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    @neilCooke

    @opPattern: INVALID_INPUT

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,396
    edited May 2023
    opPattern(context, id + "patternB", {
                        "entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
                        "transforms" : computedTransforms1,
                        "instanceNames" : instanceNames
                    });

    Senior Director, Technical Services, EMEAI
  • Options
    ben_partouchben_partouch Member Posts: 95 PRO
    Should have seen this one!..... Thank you @NeilCooke!

  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 PRO
    Should have seen this one!..... Thank you @NeilCooke!

    Oops. That's on me. Glad you got it working.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.