<p>Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.</p></p><strong>First time visiting? Here are some places to start:</strong></p><ol style="list-style:inherit;margin-left:25px;"><li>Looking for a certain topic? Check out the <a href="https://forum.onshape.com/categories">categories filter</a> or use Search (upper right).</li><li>Need support? <a href="https://forum.onshape.com/post/question/community-support">Ask a question</a> to our <a href="https://forum.onshape.com/categories/community-support">Community Support</a> category.</li><li>Please submit support tickets for bugs but you can request improvements in the <a href="https://forum.onshape.com/categories/product-feedback">Product Feedback category</a>.</li><li>Be respectful, on topic and if you see a problem, Flag it.</li></ol><p>If you would like to contact our Community Manager personally, feel free to <a href="https://forum.onshape.com/profile/6/LouGallo">send a private message</a> or <a href="mailto:lgallo@onshape.com">an email</a>.
</p>

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

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    Answer ✓
    Just use qCreatedBy(id) for all bodies created in the current feature. 
    Senior Director, Technical Services, EMEA

Answers

  • konstantin_shiriazdanov
    konstantin_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);

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    Answer ✓
    Just use qCreatedBy(id) for all bodies created in the current feature. 
    Senior Director, Technical Services, EMEA
  • monroe_weber_shirk
    monroe_weber_shirk Member Posts: 103 EDU
    Elegant! Thank you!