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 EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com