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.

How to create a query that will select a specific edge of a part?

cory_isaacsoncory_isaacson Member, Developers Posts: 43 PRO
I have a part that is a rectangle that is 1/4" thick after extrusion. In FeatureScript I need to select the corner edge (the 1/4" thickness, no other edges). This is so I can keep the part flat but Fillet the corner (just the vertical edge). I can do this manually be don't know how to create a FS query to do the same thing.

If someone could provide a FS query example to do this that would be great.

Best Answer

Answers

  • shashank_aaryashashank_aarya Member Posts: 265 ✭✭✭
    Hi @cory_isaacson I am also learning the feature script programming through the feature script documentation. So, I may not precisely correct in this answer. Try following lines just for a reference. It is not a complete program. You can modify it as per your requirement.

    FeatureScript 464;
    import(path : "onshape/std/geometry.fs", version : "464.0");

    annotation { "Feature Type Name" : "Extrude1" }
    export const extrude1 = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "My Query", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.myQuery is Query;
            annotation { "Name" : "My Length" }
            isLength(definition.myLength, LENGTH_BOUNDS);


        }
        {
            opExtrude(context, id + "extrude1", {
                        "entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
                        "direction" : evOwnerSketchPlane(context, { "entity" : qCreatedBy(id + "extrude1", EntityType.BODY) }).normal,
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : 1 * inch

                    });
            opThicken(context, id + "thicken1", {
                        "entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
                        "thickness1" : 0.1 * inch,
                        "thickness2" : 0.1 * inch
                    });
            opBoolean(context, id + "boolean1", {
                        "tools" : qCreatedBy(id + "extrude1", EntityType.BODY),
                        "operationType" : BooleanOperationType.UNION
                    });
        });

    Highlighted lines in Italic and bold format are query for edge selection. I am still in the learning phase of FS programming. You can also share your ideas if something needs to be corrected in above lines.

    Thanks
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    I think the OP is asking for a query rather than for the user to do a selection.  I can't picture from the description which exact edge is required (without a document link), but I can suggest computing a 3D point that should be on the edge and using qContainsPoint or using something like qSmallest and qFarthestAlong to filter out the qCreatedBy edges.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • cory_isaacsoncory_isaacson Member, Developers Posts: 43 PRO
    Thanks, I am close now, this almost works. The section with the comments: // This resolves to nothing is not finding the edge between the two points (or all the edges on the part). I checked and my points are both correct and valid (they are highlighted when I debug). FYI, my logMessage function just calls debug with some other text in println to make it easier to read.

    So the question now is: How can I select the edge between the two points?

    // Query for the part.
        var partQuery is Query = qCreatedBy(id + value.extrudeName, EntityType.BODY);
        logMessage(context, "partQuery", partQuery);
       
        // This resolves to nothing.
        var linesQuery is Query = qGeometry(partQuery, GeometryType.LINE);
        logMessage(context, "linesQuery", linesQuery);
       
        // Build the vector for the bottomUpperLeft and topUpperLeft points.
        var bottomUpperLeft is Vector = vector(value.xLeft, value.yUpperLeft, value.planeOffset);
        var topUpperLeft is Vector = vector(value.xLeft, value.yUpperLeft, value.planeOffset + value.partThickness);
        logMessage(context, "bottomUpperLeft", bottomUpperLeft);
        logMessage(context, "topUpperLeft", topUpperLeft);
       
       
        // Build the full query using qContainsPoint. This returns the entire body.
        var upperLeftPointsQuery is Query = qContainsPoint(qContainsPoint(partQuery, bottomUpperLeft), topUpperLeft);
        logMessage(context, "upperLeftPointsQuery", upperLeftPointsQuery);
       
        // Query for the line between the points.
        // This resolves to nothing.
        var upperLeftEdgeQuery is Query = qGeometry(upperLeftPointsQuery, GeometryType.LINE);
        logMessage(context, "upperLeftEdgeQuery", upperLeftEdgeQuery);

    Here is the debug output:
    partQuery
    debug: Query resolves to 1 bodies
    linesQuery
    debug: Query resolves to nothing
    bottomUpperLeft
    debug: Vector (-0.0381 meter, 0.2921 meter, 0 meter)
    topUpperLeft
    debug: Vector (-0.0381 meter, 0.2921 meter, 0.006350000000000001 meter)
    upperLeftPointsQuery
    debug: Query resolves to 1 bodies
    upperLeftEdgeQuery
    debug: Query resolves to nothing
    Result: Regeneration complete


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    The problem is that querying for a body doesn't query for all entities owned by the body (i.e. its edges, faces, etc.).  So if you replace partQuery with qOwnedByBody(partQuery) it should work.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • cory_isaacsoncory_isaacson Member, Developers Posts: 43 PRO
    edited January 2017
    OK, now the query is correct (I see the proper edge in the highlight when debugging). But the fillet does not do anything. Can you see why it doesn't work?


    // Query for the part.<br>    var bodyQuery is Query = qCreatedBy(id + value.extrudeName, EntityType.BODY);<br>    logMessage(context, "bodyQuery", bodyQuery);<br>    <br>    // Get all components owned by the bodyQuery.<br>    var partQuery is Query = qOwnedByBody(bodyQuery);<br>    // logMessage(context, "partQuery", partQuery);<br>    <br>    // var linesQuery is Query = qGeometry(partQuery, GeometryType.LINE);<br>    // logMessage(context, "linesQuery", linesQuery);<br>    <br>    // Build the vector for the bottomUpperLeft and topUpperLeft points.<br>    var bottomUpperLeft is Vector = vector(value.xLeft, value.yUpperLeft, value.planeOffset);<br>    var topUpperLeft is Vector = vector(value.xLeft, value.yUpperLeft, value.planeOffset + value.partThickness);<br>    logMessage(context, "bottomUpperLeft", bottomUpperLeft);<br>    logMessage(context, "topUpperLeft", topUpperLeft);<br>    <br>    <br>    // Build the full query using qContainsPoint. This returns the entire body.<br>    var upperLeftPointsQuery is Query = qContainsPoint(qContainsPoint(partQuery, bottomUpperLeft), topUpperLeft);<br>    logMessage(context, "upperLeftPointsQuery", upperLeftPointsQuery);<br>    <br>    // Query for the line between the points.<br>    var upperLeftEdgeQuery is Query = qGeometry(upperLeftPointsQuery, GeometryType.LINE);<br>    logMessage(context, "upperLeftEdgeQuery", upperLeftEdgeQuery);<br>    <br>    // Perform the fillet.<br>    opFillet(context, id + "fillet1", {<br>                "entities" : upperLeftEdgeQuery,<br>                "radius" : value.filletRadius<br>    });



  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    You are right -- that is a gap in the docs and tutorials -- and it is something likely to be unfamiliar to people of all backgrounds.  We'll put something together and ask for your feedback.  @kevin_o_toole_1
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.