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.

How to query a sketch in the preconditions?

traveler_hauptmantraveler_hauptman Member, OS Professional, Mentor, Developers Posts: 419 PRO
I'd like the user to grab a sketch as one of the parameters. This can be done with the provided extrude tool, but I can't figure out what filter combination will allow this in featurescript. I tried bisecting qEverything with a heap of filters and my best guess is that sketches are not in qEverything. But since the extrude tool can see sketches, they must be somewhere....

My goal is to grab all points in the sketch, regardless of count. Group selecting individual points is not the same because the feature would need to be manually updated if the user changes the sketch.



  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 928
    This is actually a bit more tricky than I like -- extrude is a different case because it wants sketch *regions* not sketches themselves.  Here's what I came up with (using the feature list parameter that's also used in feature patterns).  The downside is that the UI does not prevent you from selecting features that are not sketches -- I think we have some filtering work to do.

    annotation { "Feature Type Name" : "My Feature" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
            annotation { "Name" : "Sketches" }
            definition.sketches is FeatureList;
            var queries = [];
            for (var entry in definition.sketches) // keys are feature ids
                queries = append(queries, qCreatedBy(entry.key, EntityType.VERTEX));
            const pointQuery = qBodyType(qUnion(queries), [BodyType.WIRE, BodyType.POINT]);
            // Now pointQuery has all the points of all the selected sketch wire bodies (sketch entities)
            // Keep in mind that when you have two sketch curves meet at a vertex, you will have two vertices (one for each) not one.  clusterPoints may help if that's a problem.
            debug(context, pointQuery);
        }, { /* default parameters */ });

    Ilya Baran \ Director, Architecture and FeatureScript \ Onshape Inc
  • traveler_hauptmantraveler_hauptman Member, OS Professional, Mentor, Developers Posts: 419 PRO
    Nice! I hadn't found FeatureList yet. I should be able to exclude most non-sketch features based on their contents.
Sign In or Register to comment.