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.

Order of split body parts

graham_lockgraham_lock Member Posts: 160 PRO

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

  • EvanReeseEvanReese Member, Mentor Posts: 2,188 ✭✭✭✭✭
    edited December 16 Answer ✓

    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 Reese

Answers

  • eric_pestyeric_pesty Member Posts: 1,951 PRO

    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…

  • graham_lockgraham_lock Member Posts: 160 PRO

    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?

  • graham_lockgraham_lock Member Posts: 160 PRO

    So, I'm now taking the output from evaluateQuery and sorting it based on evBox3d minCorner of each body - seems to work.

  • EvanReeseEvanReese Member, Mentor Posts: 2,188 ✭✭✭✭✭
    edited December 16 Answer ✓

    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 Reese
  • graham_lockgraham_lock Member Posts: 160 PRO

    Thank you for those ideas - I’ll experiment and get back!

  • graham_lockgraham_lock Member Posts: 160 PRO

    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!

Sign In or Register to comment.