Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

Finding which face the triangles belong to

2 REPLIES 2
SOLVED
Message 1 of 3
287 Views, 2 Replies

Finding which face the triangles belong to

Hi,

Is there a way to find out which triangles in a generated mesh correspond to which BRep faces?

I'd like to have a set of faces and a corresponding set of the generated triangles for each face. I need to do this for all of the triangles, not just a single one. Of course, I can generate the mesh for each face separately, but I need the resulting mesh to be watertight/manifold and I don't believe there is any guarantee (or I can't find one ) that in the seams between the meshes the same vertices will be used.

Can anyone help me with this?

Thanks,

Jeremy

2 REPLIES 2
Message 2 of 3

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:
ui  = app.userInterface

face = ui.selectEntity("Select a BRepFace", "Faces").entity;

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

Message 3 of 3