Queries can be one of the most challenging parts when learning how to develop Custom Features. Queries are used in FeatureScript to reference entities within the model's context for use within a custom feature.

To help with this, Onshape has developed a custom feature called the Query Explorer. It utilizes the debug function to indicate (in red) the selection that results from the parameters you put in. 

You can add the Query Explorer to your Onshape toolbar by using the link here.

Once added to the toolbar, you can execute the Query Explorer feature. When the feature parameter dialog initially shows, every entity in the context of the Part Studio is highlighted in red. 

Here is a brief description of each of the feature inputs:

  • Seed — The seed is a selection to base all the following filters on. Options are everything, select entities or select features.

  • EntityType — Filters the seed input and (depending on the query) resulting selection to a specific type. Options are any, vertex, edge, face and body.

  • BodyType — Filters the bodies by topological type. Options are any, point, wire (curve), sheet (plane) and solid. 

  • Query filter 1 and 2 —  This lists all the filter actions you can use in the query. A full list of each action and their results are found in the Standard Library documentation.

  • Units — Units to use in the query if needed. Queries where units are needed include qIntersectsline, qParallelPlane, qIntersectsPlane, etc.

  • Result — This droplist decides how the resulting query is displayed. The default report shows it in a blue pop-up box in the top center of the viewport. Selecting notices will show it in the FeatureScript notices pane. Variable adds a new input to the feature with the final query.

Use the inputs to further filter down the results until only the items you want are highlighted in red. For example, if you need all the faces that bound a selected face at an edge, select the following:

Because the result selector is set to report, the resulting query will show at the top in blue. 

Highlight the text and paste it into your FeatureScript. Replace the seed (seed1_REPLACE_ME) with the actual entity to use as the reference. It could be a query parameter that the user selects, or it could also be defined elsewhere in your custom feature.

Watch the video below for more on Query Explorer:


Add the Query Explorer to your Onshape toolbar here.

Interested in learning more Onshape Tech Tips? You can review the most recent technical blogs here.