Order of split body parts

graham_lock
graham_lock Member Posts: 277 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

  • EvanReese
    EvanReese Member, Mentor Posts: 3,086 PRO
    edited December 2024 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com

Answers

  • eric_pesty
    eric_pesty Member, pcbaevp Posts: 2,905 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_lock
    graham_lock Member Posts: 277 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_lock
    graham_lock Member Posts: 277 PRO

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

  • EvanReese
    EvanReese Member, Mentor Posts: 3,086 PRO
    edited December 2024 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • graham_lock
    graham_lock Member Posts: 277 PRO

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

  • graham_lock
    graham_lock Member Posts: 277 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!