<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>
</p>
How can I make a composite part of all of the bodies I create in a feature?
monroe_weber_shirk
Member Posts: 103 EDU
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, {and then used
"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?
0
Best Answer
-
Just use qCreatedBy(id) for all bodies created in the current feature.
Senior Director, Technical Services, EMEA1
Answers
-
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 idtickBodies = 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);
0 -
Just use qCreatedBy(id) for all bodies created in the current feature.
Senior Director, Technical Services, EMEA1 -
Elegant! Thank you!
0


