How to choose which body to select in feature script

CAD_SSP
CAD_SSP Member Posts: 45 ✭✭
I am trying to use the selection of 2 faces on one part to reliably select another part alongside it, and if there are 2 parts adjoining it then I want to be able to select which one I want using a boolean input.

To my way of thinking the example below does not work as I would expect it to, both of the "Hinge" features select the part nearest the "back" but I would have thought it more logical if one selected the back one and the other the front...

example:  https://cad.onshape.com/documents/7e271c1b4713b16b58063150/w/582c06d1a4c282d4bf39b5e8/e/aa474d081cdf011d56ad7571

I have been through all the queries I can think of to try and determine which part I want without any success, I can successfully get a coordinate system that works as I would expect it to:

utilising the Normal to face on the side faces - evSurfaceDefinition(context, {"face" : definition.sideFace}).normal and creating a coordinate system based on that, But I have no idea how to use this to determine which of the side panels I want it to select.

Any help much appreciated.

Tagged:

Best Answer

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,276 image
    Answer ✓
    Have you tried using qFarthestAlong with the normal direction (or the negative normal direction, depending on your boolean flag)?  Make sure that what you pass to qFarthestAlong is a query that resolves to your two candidate bodies (and nothing else).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc

Answers

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,276 image
    Answer ✓
    Have you tried using qFarthestAlong with the normal direction (or the negative normal direction, depending on your boolean flag)?  Make sure that what you pass to qFarthestAlong is a query that resolves to your two candidate bodies (and nothing else).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • CAD_SSP
    CAD_SSP Member Posts: 45 ✭✭
    @ilya_baran Thanks very much for that, worked a treat, have updated the example and will leave it for anyone else who needs it.