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.

Options

Deleting Multiple Sketches with one opDeleteBodies???

Stormi_BackusStormi_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

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,415
    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, EMEAI

Answers

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,415
    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, EMEAI
Sign In or Register to comment.