How do I determine if two faces mate?

How do I determine if two faces mate?

markusbarnes
Advocate Advocate
433 Views
2 Replies
Message 1 of 3

How do I determine if two faces mate?

markusbarnes
Advocate
Advocate

I would like to create a new plane between two mating (touching, adjacent?) faces of two component bodies as shown in the subsequent image. The faces are not mated using the Mates Feature, but are simply formed when a profile sketch on one body's face is extruded into a new body. 

 

Screenshot 2025-02-01 at 10.33.31 AM.png

I've managed to complete the following steps:

  • Query all the faces between the two components
  • Filter the result for all parallel faces between the two component bodies

For the final step, I having difficulty determining the criteria for mating faces. It's unclear whether it's based on coplanarity, where there's no spacing between the faces, or adjacency, where the faces are spaced apart based on some tolerance. 

 

How is this determined? Is there a more efficient way to achieve what I am doing? Does the Fusion API provide a facilities for what I am doing?

0 Likes
Accepted solutions (1)
434 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

Here's some code I put together that I believe does what you want.

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent
        occs = root.allOccurrences

        mated = []
        for i in range(occs.count):
            occ1 = occs[i]
            for j in range(i + 1, occs.count):
                occ2 = occs[j]

                if CheckIfMated(occ1, occ2):
                    mated.append([occ1, occ2])

        if len(mated) == 0:
            app.log('No mates were found.')
        else:
            for mate in mated:
                app.log(f'{mate[0].name} is mated to {mate[1].name}.')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def CheckIfMated(occ1: adsk.fusion.Occurrence, occ2: adsk.fusion.Occurrence) -> bool:
    app = adsk.core.Application.get()
    mm = app.measureManager

    # Build a list of all planar faces and their normals in occurrence 1.
    occ1Faces = []
    for body in occ1.bRepBodies:
        for face in body.faces:
            if face.geometry.objectType == adsk.core.Plane.classType():
                (_, normal) = face.evaluator.getNormalAtPoint(face.pointOnFace)
                occ1Faces.append([face, normal])

    # Build a list of all planar faces and their normals in occurrence 2.
    occ2Faces = []
    for body in occ2.bRepBodies:
        for face in body.faces:
            if face.geometry.objectType == adsk.core.Plane.classType():
                (_, normal) = face.evaluator.getNormalAtPoint(face.pointOnFace)
                occ2Faces.append([face, normal])

    # Compare each face in occurrence 1 with those in occurrence 2 to see
    # if their normals are 180 deg. opposed and if they are coincident.
    for i in range(len(occ1Faces)):
        occ1Face = occ1Faces[i][0]
        occ1Normal: adsk.core.Vector3D = occ1Faces[i][1]
        for j in range(len(occ2Faces)):
            occ2Face = occ2Faces[j][0]
            occ2Normal: adsk.core.Vector3D = occ2Faces[j][1]

            # Check if the normals are opposing each other within a tolerance.
            if math.fabs(occ1Normal.angleTo(occ2Normal) - math.pi) < app.vectorAngleTolerance:
                # Check distance between the faces to see if it's a minimum distance to be considered coincident.
                results = mm.measureMinimumDistance(occ1Face, occ2Face)
                if results.value <= app.pointTolerance:
                    return True

    return False
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

markusbarnes
Advocate
Advocate

Thanks!

0 Likes