Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Order of split body parts
Hi,
I have a simple rectangular part which is split into a number of sections using planes and opSPlitPart.
After the splits I need to walk the generated parts in the order in which they were created.
My body which is split is definition.intersect and I currently have the following code:
for (var body in evaluateQuery(context, qOwnedByBody(definition.intersect, EntityType.BODY)))
{…}
But as evaluateQuery doesn't guarantee any particular order of retrieval I'm trying to work out the best way to walk the split parts essentially as an ordered array.
Any help appreciated.
Thank you.
Best Answer
-
EvanReese Member, Mentor Posts: 2,188 ✭✭✭✭✭
The box method can work, but I have a hunch there's something better. Here are some untested ideas:
Since you're splitting with planes perhaps you can add a qCoincidesWithPlane() or qInFrontOfPlane() to your loop, then append that query to an array as you go.
qSplitBy() should return both of the new split parts. You might need to use qIntersection() with the method above to return only the one body you're after.
Failing that, you might look into evRaycast(), which I think returns things in order.
Evan Reese1
Answers
Not an expert but my first thought would be do use a loop to do each split so you can keep track of the bodies…
Thank you.
I am actually using a loop but opSplitPart only seems to generate new faces, not bodies.
It just feels as though I'm missing something in how to gather the new bodies as they're created?
So, I'm now taking the output from evaluateQuery and sorting it based on evBox3d minCorner of each body - seems to work.
The box method can work, but I have a hunch there's something better. Here are some untested ideas:
Since you're splitting with planes perhaps you can add a qCoincidesWithPlane() or qInFrontOfPlane() to your loop, then append that query to an array as you go.
qSplitBy() should return both of the new split parts. You might need to use qIntersection() with the method above to return only the one body you're after.
Failing that, you might look into evRaycast(), which I think returns things in order.
Thank you for those ideas - I’ll experiment and get back!
So, qSPlitBy works well.
I didn't get qCoincidesWithPlane or qInFrontOfPlane to work properly - I think I'll return to them as an exercise though since I've never used them before. I'll post back if I get anywhere.
I don't think evRayCast fits easily with my code.
I have a better solution than my initial sort so thank you!