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.

Featurescript - in a sketch how to determine if point is on a face

ian_mctavishian_mctavish Member Posts: 7 EDU

I'm trying to create a featurescript that creates a 1" grid of points on a face. If the selected face is parallel to the top plane I can easily find the minimum and maximum x and y values. What I am struggling with is if the face is in a different orientation - how do I determine the minimum/maximum values of x and y in relation to the sketch?

Comments

  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO

    If you are trying to find if a point is on a face, you have two options:
    qContainsPoint(face,point), and then check if the query is empty with isQueryEmpty()
    or
    evDistance() and check if the face/point distance is zero

    If you want to find the bounds of the face, you can use evBox3d(), and specify the coordinate system of the sketch.

    Without knowing the specifics of what you are trying to accomplish, hard to know which to recommend, but that should help at least a little bit.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • ian_mctavishian_mctavish Member Posts: 7 EDU

    Caden,

    Thanks, I am trying qContainsPoint. Here is the code I am using:

    //facePlane is Plane tangent to the selected face: definition.targetFace
    //definition.targetFace is a query from a face that the user selects
    var vectorToCheck is Vector = planeToWorld(facePlane, vector(0,0)*inch);
    var pointToCheck = toWorld(planeToCSys(facePlane), vectorToCheck);
    println(qContainsPoint(definition.targetFace, pointToCheck));
    println("");
    println(isQueryEmpty(context, qContainsPoint(definition.targetFace, pointToCheck)));

    Now vectorToCheck should be on the face, however I am getting true for the isQueryEmpty (full output below). Thanks for any insights you can provide.

    { point : [ 1.1102230246251565e-16 , 0 , 0.006350000000000001 ] , queryType : CONTAINS_POINT , subquery : { queryType : UNION , subqueries : [ { disambiguationData : [ { disambiguationType : ORIGINAL_DEPENDENCY , originals : [ { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : g1bWyhonVgaM.bottom } , { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : g1bWyhonVgaM.top } , { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : g1bWyhonVgaM.left } , { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : L8eKFDnIzZjc0.MirrorCS } , { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : 7Wii66VG1rhd0.MirrorCS } , { entityType : EDGE , historyType : CREATION , operationId : [ Fo1W4E0qGbUNqs8_0.wireOp ] , queryType : SKETCH_ENTITY , sketchEntityId : Je0q0qDnAOdG0.MirrorCS } ] } ] , entityType : FACE , historyType : CREATION , isStart : false , operationId : [ Fu4c1LKMRjZ3SBK_0.opExtrude ] , queryType : CAP_FACE } ] } }

    true

  • Caden_ArmstrongCaden_Armstrong Member Posts: 195 PRO

    Have you done addDebugPoint and addDebugEntity to see if the point you are checking really is on the target face?

    You can also sanity check with evDistance and see if the distance is zero.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • ian_mctavishian_mctavish Member Posts: 7 EDU

    I got it working - I should have used vectorToCheck instead of pointToCheck. Thanks so much!

Sign In or Register to comment.