Find Self-Intersecting Faces of a Selected Mesh

Howdy Ya’ll
Thought I’d dump this up here. Its a script made that generates surfaces wherever self intersection occurs on a mesh. Hopefully somebody finds use of it in the future!

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino

def get_clashing_faces(mesh_id):
    mesh = rs.coercemesh(mesh_id)
    if not mesh:
        return None
    
    # Value of -1 will get all clashing faces
    clashing_faces = mesh.Faces.GetClashingFacePairs(-1)
    
    if not clashing_faces:
        return None
    
    return clashing_faces

def create_surfaces_on_clashing_faces(mesh, clashing_faces):
    for pair in clashing_faces:
        for face_index in [pair.I, pair.J]:
            face = mesh.Faces[face_index]
            vertices = [mesh.Vertices[i] for i in face]
            if len(vertices) == 3:
                vertices.append(vertices[2]) 
            # Make it a quad by repeating the last vertex
            corner_points = [rs.AddPoint(v) for v in vertices]
            if len(corner_points) == 4:
                rs.AddSrfPt(corner_points)
            for point in corner_points:
                # Clean up points
                rs.DeleteObject(point)

mesh_id = rs.GetObject('Select a mesh', rs.filter.mesh)
if mesh_id:
    clashes = get_clashing_faces(mesh_id)
    if clashes:
        mesh = rs.coercemesh(mesh_id)
        create_surfaces_on_clashing_faces(mesh, clashes)
    else:
        print('No clashing faces found.')
else:
    print('No mesh selected.')
1 Like