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.

Options

How can I determine the entity or geometry type of a selected entity?

joshtargojoshtargo Member Posts: 340 EDU

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

  • jelte_steur814jelte_steur814 Member Posts: 495 PRO
    edited July 14

    check out:

    evCurveDefinition

    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 ConeCylinderPlaneSphereTorus, or BSplineSurface as appropriate for the face, or an unspecified map value if the face is none of these with surfaceType filled of type SurfaceType

  • joshtargojoshtargo Member Posts: 340 EDU

    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.

  • MichaelPascoeMichaelPascoe Member Posts: 2,412 PRO
    edited July 14

    @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.


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • joshtargojoshtargo Member Posts: 340 EDU

    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"

  • MichaelPascoeMichaelPascoe Member Posts: 2,412 PRO
    edited July 14

    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;
      }
    }
    
    

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • joshtargojoshtargo Member Posts: 340 EDU

    its similar to what I ended up doing, I guess there is no built in function that returns an entity type, which seems strange.

Sign In or Register to comment.