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 can I make a composite part of all of the bodies I create in a feature?

I'm writing a feature script to create a ruler or a scale that includes tick marks and numbers. I want to combine all of the ticks and numbers into a single composite part at the end of the feature script.
I first tried
 opCreateCompositePart(context, id, {
            "bodies" : qAllModifiableSolidBodies(),
            "closed" : false
        });
but that put all of the bodies in the part studio into the composite and I only want the parts created in this feature to be in the composite.
I tried creating an array of all of the bodies as I create them.
            tickbodies[i] = qCreatedBy(currentID + "tick", EntityType.BODY);
and then used
opCreateCompositePart(context, id, {
                    "bodies" : tickbodies,
                    "closed" : true
                });
That fails because "bodies" is not expecting an array.

What is the elegant way of putting all of these ticks and numbers into a composite part?

Best Answer

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
    Answer ✓
    Just use qCreatedBy(id) for all bodies created in the current feature. 
    Senior Director, Technical Services, EMEAI

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited January 2021
    presumably you creating tick bodies in a loop? if so then before loop you need to define an empty array:
    var tickBodies=[];
    //then if the loop you create new body with operation id depending on some "i" and you append the query of that body to the array.
    for (var i=0, i<N, i+=1; )
    {
    //here you apply some operations creating new body with body creation operation id: id+("tickBody"~i)

    //here you appending array with operation id
    tickBodies = append(tickBodies, qCreatedBy(id+("tickBody"~i), EntityType.BODY));
    }
    //and finally outside of the loop you turn array of queries into the query for multiple bodies wich you can pass to opCreateCompositePart()
    tickBodies = qUnion(tickBodies);

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
    Answer ✓
    Just use qCreatedBy(id) for all bodies created in the current feature. 
    Senior Director, Technical Services, EMEAI
  • monroe_weber_shirkmonroe_weber_shirk Member Posts: 96 EDU
    Elegant! Thank you!
Sign In or Register to comment.