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.
How can I determine the entity or geometry type of a selected entity?
Do I need to have a qGeometry for every possible type, or is there a way for it to just look at a query and tell me what it is?
Comments
-
check out:
and
evSurfaceDefinition (context is Context, arg is map) returns map
Return a descriptive value for a face, or the first face if the query finds more than one. Return a
Cone,Cylinder,Plane,Sphere,Torus, orBSplineSurfaceas appropriate for the face, or an unspecified map value if the face is none of these with surfaceType filled of type SurfaceType1 -
I was hoping there was a function that simply tells you what kind of entity something is. I want the user to be able to click on a vertex, edge, arc, circle, or face, but the processing is different depending on which one it is.
0 -
@joshtargo Well, there is, it's qEntityType. But that gets you one of the following: Vertex, Edge, Face, or Body. If you want it to return the geometry type, you could do qGeometryType. If you want the body type then qBodyType. I recommend making a custom function to use all of them together to return a custom type from a custom enum. You can do the initial filtering with qEntityType, then from there use evCurveDefinition or evSurfaceDefinition to get specifics.
I imagine you could do it in 10 minutes 😎. Then save it to your FS library where you can import it and re-use it per project.
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________0 -
Do t I need to use the specific types I'm looking for as arguments for those functions? I wanted something that returns "vertex" or "arc"
0 -
If you want the query for specific entity types, you can do something like this:
const vertexQuery = qEntityFilter(queryToFilter, EntityType.VERTEX)); const edgeQuery = qEntityFilter(queryToFilter, EntityType.EDGE)); const faceQuery = qEntityFilter(queryToFilter, EntityType.FACE)); const bodyQuery = qEntityFilter(queryToFilter, EntityType.BODY)); const isVertex = !isQueryEmpty(context, vertexQuery)); const isEdge = !isQueryEmpty(context, edgeQuery)); const isFace = !isQueryEmpty(context, faceQuery)); const isBody = !isQueryEmpty(context, bodyQuery));
For finding an arc it could be more like this:
// No doubt there are cleaner ways to do this, I'm just throwing something out there for you to start. // Also, the try catch doesn't work well, so perhaps this isn't the best approach. // I would expect the "try" to forget the attempt if it fails, but for some reason this isn't // the case with FeatureScript, which makes the try/catch pointless if it will not consistently trigger the // catch and forget what happened in the try. As you can tell… I've had some bones to pick in the past with FS try/catch. const isEdge = !isQueryEmpty(context, qEntityFilter(queryToFilter, EntityType.EDGE))); var isArc = false; if (isEdge) { try silent { var radius = evCurveDefinition(context, { "edge" : definition.entitiesArray[0] }).radius; isArc = true; } }
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________0 -
its similar to what I ended up doing, I guess there is no built in function that returns an entity type, which seems strange.
0 -
My solution was:
0


