How about to check if the three points of each triangle are on the face? If the three points of one triangle are all on the face, the triangle is on the face. I wrote a function “isTriangleOnFace”, hope it’s helpful.
import adsk.core, adsk.fusion, adsk.cam, traceback
# point0, point1, point2 - Point3D object, point of triangle
# face - BRepFace object
def isTriangleOnFace(point0, point1, point2, face):
# Get surface evaluator of the face
eva = face.evaluator
# Get the parameter positions that correspond to a set of points on the surface
# If the points do not lie on the surface, the parameter of the nearest point on the surface will generally be returned
(retVal, params) = eva.getParametersAtPoints([point0, point1, point2])
if len(params) != 3:
return False
# Check if the parameters are out of the extent of the face
if not eva.isParameterOnFace(params[0]) or not eva.isParameterOnFace(params[1]) or not eva.isParameterOnFace(params[2]):
return False
# The returned points should be on the face
retPoints = None
(retVal, retPoints) = eva.getPointsAtParameters(params)
if len(retPoints) != 3:
return False
return point0.isEqualTo(retPoints[0]) and point1.isEqualTo(retPoints[1]) and point2.isEqualTo(retPoints[2])
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
face = ui.selectEntity("Select a BRepFace", "Faces").entity;
triangle0 = [adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(1, 0, 0), adsk.core.Point3D.create(0, 1, 0)]
ret = isTriangleOnFace(triangle0[0], triangle0[1], triangle0[2], face)
ui.messageBox('isTriangleOnFace: ' + str(ret))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Jack