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.

Confusion over query (list).

jrs_spedleyjrs_spedley Member Posts: 70 ✭✭
I only want to do a simple featurescript but I'm getting stuck with Queries.

I find Extrude is annoyingly selective on which edges it will extrude into surfaces.  To get around it I want to loop through a 'query' of edges and extrude and thicken them individually, then form a union into a single part.  e.g. like a sketch of a spider's web.
The problems is when I try to loop through the query using "for (var edge in edges)" it often fails because 'edge' isn't an EDGE. 

I've tried to use qEntityFilter but then I just get the whole previous query wrapped in another qEntityFilter query.

Am I missing something here, is a query just an array of key:value pairs where 'value' can be another list of key:value pairs?

Here is the basic output ...
for (var edge in definition.edges)
	println(edge);

outputs ...
{ key : queryType , value : UNION }
{ key : subqueries , value : [ { entityType : EDGE , historyType : CREATION , operationId : [ F3jrPebnT9OxNT9_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : 2fa71c56-ffcc-4f50-be0c-e0d57dd11eba } , { entityType : EDGE , historyType : CREATION , operationId : [ F3jrPebnT9OxNT9_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : 8f7c92d3-5654-4301-92fe-92ca18b45d8c } ] }

but what I [think I] want is  ...
{ entityType : EDGE , historyType : CREATION , operationId : [ F3jrPebnT9OxNT9_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : 2fa71c56-ffcc-4f50-be0c-e0d57dd11eba }
{ entityType : EDGE , historyType : CREATION , operationId : [ F3jrPebnT9OxNT9_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : 8f7c92d3-5654-4301-92fe-92ca18b45d8c }
I'm actually going slightly insane now !!!!


Comments

  • jakeramsleyjakeramsley Member, Moderator, Onshape Employees, Developers Posts: 581
    Here is our documentation of queries, which can explain it more in-depth and technical than I can:

    https://cad.onshape.com/FsDoc/library.html#module-query.fs
    FeatureScript Documentation:

    Functions for constructing queries. Features that take queries as inputs should re-export this module.

    Queries are used to refer to topological entities (vertices, edges, faces, and bodies) that FeatureScript operation and evaluation functions work on. A query is a map that contains instructions for how to find entities. For example, a query for all edges in a context looks like qEverything(EntityType.EDGE). Many queries can take subqueries as arguments, allowing for more complex nested queries.

    Queries in general do not contain a list of entities in any form. Rather, they contain criteria that specify a subset of the topological entities in a context. To get an array of the entities (if any) which match a query in a context, use evaluateQuery. There is no need to evaluate a query before passing it into a function, including any of the Standard Library's operation and evaluation functions.

    There are two general types of queries: state-based and historical. State-based queries select entities based on the model state, e.g. "All edges adjacent to a cylindrical face which touches this point." Historical queries select entities based on the model history, e.g. "the edge that was generated by feature extrude_1_id from sketch vertex vertex_id from sketch sketch_id." State-based queries cannot refer to entities that have been deleted. Most automatically-generated queries are historical, while queries more commonly used in manually written code are state-based.

    I've bolded, which I believe is problem in what you are trying to filter as I only have a snippet of your code and summary of what you are trying to do.

    If you explain a bit more in detail, we may be able to help more with an approach to writing your FeatureScript
    Jake Ramsley

    Director of Quality Engineering              onshape.com
  • jrs_spedleyjrs_spedley Member Posts: 70 ✭✭
    Exactly what I was looking for, thanks.  Totally forgot about evaluateQuery but it is only my second featurescript!

    Thanks.

    P.S.  it also clears up what a query is, it isn't the result you want but the way to get the result you want.  Much like database access.  I suppose you can create complex queries and then internally onshape can simplify them or buffer calculations to produce more efficient results.
Sign In or Register to comment.