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.

Featurescript - query/delete all sketches

leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
I want to clean up my Part Studio, so that when I derive it in another (using opMergeContexts in FeatureScript) I don't get all the sketches and points and all, but I do want to import all parts and surfaces at once.

Either I can query these one by one, calling opDeleteBodies on all the queries, but I'd really like a smoother version where I don't select these by hand, but automatically query them.

Can anybody point me in the right direction for querying all sketches at once?
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
Tagged:

Best Answer

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    In the next release, we expect to have a convenient query filter for sketches.  Currently, I'm not aware of a way to avoid querying for the sketches one by one by id.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Would qBodyType work using WIRE?
    Senior Director, Technical Services, EMEAI
  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
    Filtering a query (all WIRE and SHEET bodies, and VERTEX entities) using evOwnerSketchPlane() works excellent. Thanks.
    var qAllSketchEntities = qUnion(filter(evaluateQuery(context, qUnion([qBodyType(qEverything(), BodyType.WIRE), qBodyType(qEverything(), BodyType.SHEET), qEverything(EntityType.VERTEX)])), function(entity)
        {
            if (try silent(evOwnerSketchPlane(context, { "entity" : entity })) != undefined)
                return true;
            else
                return false;
        }));
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    edited April 2017
    I simplified your code to this:
    var qAllSketchEntities = qUnion(filter(evaluateQuery(context, qEverything()), function(entity)
        {
            return (try silent(evOwnerSketchPlane(context, { "entity" : entity })) != undefined);
        }));
    It gives a different number of bodies in the result, don't know why, but it works.

    Edit: although using the profiler I see yours is faster due to not testing solid bodies.
    Senior Director, Technical Services, EMEAI
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    @NeilCooke, looks like your code goes through all entities, not just bodies.

    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    Setting it to qEverything(EntityType.BODY) picks up all sketch bodies and makes the code 3x faster too!
    Senior Director, Technical Services, EMEAI
  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
    Thanks @NeilCooke That makes perfect sense.
    I tend to think of only solids when I see "BODY", so I took some unnecessary detours in my code without thinking. 
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
Sign In or Register to comment.