Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Queries, queries and more queries ...
ron_moreland
Member Posts: 90 ✭✭
Here is a simple FS:
and here is the debug output:
I read the Docs carefully, evaluteQuery() returns an array of queries. So how do I get the things?
FeatureScript 736; import(path : "onshape/std/geometry.fs", version : "736.0"); annotation { "Feature Type Name" : "FS Test" } export const fstest = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Plane", "Filter" : GeometryType.PLANE || EntityType.FACE , "MaxNumberOfPicks" : 1 } definition.tPlane is Query; } { const thePlane = evaluateQuery(context, definition.tPlane); debug(context, "DBG1 "~ thePlane ); debug(context, "DBG2 "~ thePlane[0] ); if ( canBePlane(thePlane[0]) ) { debug(context, "Can be a Plane"); } else { debug(context, "Not a PLANE"); } } );
and here is the debug output:
debug: DBG1 [ Query : { "queryType" : QueryType : "TRANSIENT" , "transientId" : TransientId : BuiltIn: 7 } ]
debug: DBG2 Query : { "queryType" : QueryType : "TRANSIENT" , "transientId" : TransientId : BuiltIn: 7 }
debug: Not a PLANE
Result: Regeneration complete
I read the Docs carefully, evaluteQuery() returns an array of queries. So how do I get the things?
Tagged:
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215Yes, evaluateQuery just returns an array of queries, one per entity. To get information about an entity (coordinates, etc.) you need an ev function. In this case, you can use evPlane to get an actual Plane. Or you could use evFaceTangentPlane. Or evSurfaceDefinition. You could also tell if a query refers to any plane by wrapping it in a qGeometry query (with GeometryType.PLANE) and seeing if evaluteQuery of that gives you an empty array.
https://cad.onshape.com/FsDoc/modeling.html has a good overview of these concepts.
BTW, The way to tell if something is a plane is by doing
if (foo is Plane)
rather than
if (canBePlane(foo))
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
https://cad.onshape.com/FsDoc/modeling.html has a good overview of these concepts.
BTW, The way to tell if something is a plane is by doing
if (foo is Plane)
rather than
if (canBePlane(foo))
if (foo is Plane)
What is "foo"? Is it an entity? Geometry? A query? A query to an entity that might be a Plane. If you have to evaluate a query with the proper ev* to get the actual entity, how can this work if you don't know what ev* to use?
the other solution can be using try silent {} for example:
try silent
{
p = evPlane( query)
//if evPlane doesn't fails you may perform actions with p
}
try silent
{
l = evLine(query)
//if query evaluates to line evPlane failed and you are switched to this branch of code
}
In my example "foo" can be any FeatureScript value.
I would not think about it as "getting at the real entity" -- the "real" entity exists deep within the context and is impossible to "get at". The way FS works is you describe the set of entities you want to ask about using a query and then get data about these entities using ev functions -- the Plane returned by evPlane is not tied to the planar face at all -- it's just the coordinates of that plane.
One of the reasons for this design is that operations can change the "real" underlying entities in rather unpredictable ways, e.g., splitting and merging them, changing types, etc. and trying to hold on to a specific entity would not work well.
Deciding which ev to use depends on what you're trying to achieve. If you want to know know the type of face, for instance, evSurfaceDefinition will tell you. evPlane is just simpler if you happen to know that you are referencing a plane (which happens frequently -- either because of you specified a selection filter in you feature's query parameter or because you just created one or because your query is a qGeometry). Most ev functions, like evDistance or evFaceTangentPlane do not require you to know the type of geometry you're dealing with.