Deleting Multiple Sketches with one opDeleteBodies???

Stormi_Backus
Stormi_Backus Member Posts: 49 ✭
I am working on a featurescript for taper lock bushings that will have something like 50 sketches/fitSplines after I work in all available sizes/hole patterns. 

Individually deleting bodies is helpful during custom feature generation, but, imo, makes the script unnecessarily long once finalized. 

Is there a way to delete all sketch bodies within a featurescript at the end rather than having multiple instances of opDeleteBodies throughout? I can't see a way to work around the fact that all of the sketches have a different id. I guess i'm looking for a sort of 'qAllSketchEntities' if that exists...

I found an old forum post that involves accomplishing the same task for imported part studios but I am not sure how that solution would translate to my scenario: https://forum.onshape.com/discussion/6130/featurescript-query-delete-all-sketches

Thanks in advance for any guidance!

Best Answer

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    Answer ✓
    Repeating opDeleteBodies is expensive, so avoid if possible. A common way is to create an array and add bodies to delete as you go along, then call opDeleteBodies with qUnion(array). Not tried it, but I suspect this will work better:

    opDeleteBodies(context, id + "deleteSketches", {
                 "entities" : qSketchFilter(qCreatedBy(id), SketchObject.YES)
             });

    Senior Director, Technical Services, EMEA

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    Answer ✓
    Repeating opDeleteBodies is expensive, so avoid if possible. A common way is to create an array and add bodies to delete as you go along, then call opDeleteBodies with qUnion(array). Not tried it, but I suspect this will work better:

    opDeleteBodies(context, id + "deleteSketches", {
                 "entities" : qSketchFilter(qCreatedBy(id), SketchObject.YES)
             });

    Senior Director, Technical Services, EMEA