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

joshtargo
joshtargo Member Posts: 695 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_steur_info
    jelte_steur_info Member Posts: 683 PRO
    edited July 2025

    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 Cone, Cylinder, Plane, Sphere, Torus, 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

  • joshtargo
    joshtargo Member Posts: 695 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.

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,965 PRO
    edited July 2025

    @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 - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚
  • joshtargo
    joshtargo Member Posts: 695 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"

  • MichaelPascoe
    MichaelPascoe Member Posts: 2,965 PRO
    edited July 2025

    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 - Photorealistic product rendering.
    CADSharp - Professional CAD + software consulting.

    ▚▞▚▞▚▞▚▞▚
  • joshtargo
    joshtargo Member Posts: 695 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.

  • joshtargo
    joshtargo Member Posts: 695 EDU

    My solution was:

    image.png