STL Mesh Repair Script/Algorithm

Hello,
I am new to Rhino and have to do a project for my university right now. It’s about reverse engineering a part, then print it and test it. But I only have a damaged STL Mesh available.
I can repair the mesh manually or with other programs than Rhino, but if I get a slightly optimized part from my colleges and want to do the reverse engineering again, I have to start from zero again. So I want to build a reverse engineering algorithm in grasshopper for these parts. It would be very helpful to have a phyton script or something like that for grasshopper, that detects open edges, small triangles or overlapping triangles (just all kinds of errors), deletes everything in a certain radius and then remeshes the area. Is this possible and if yes, does something like this script already exist?

Thanks for your answers!

Repairing an STL file that contains errors is a complicated process and not one for which GH is designed. Your best bet to repair a broken STL file is to use a piece of software designed specifically to do that. The most reliable one I am aware of is Netfabb, but that software appears to have been sucked up into Autodesk’s Fusion360. I believe Fusion 360 is still a free product; you can find it here: Netfabb

It is also included in PrusaSlicer as a repair option for an SL file, which is how I use it. Rhino itself will create broken STL files if the object being exported is not composed entirely of closed Breps. Usually I catch these situations and fix them by tweaking my GH script, but if you are dealing with a broken STL file to begin with you’ll have to fix it directly.

I’ve done many such repairs and in almost every case the repaired STL did not differ in any significant way from the original bad STL. In the few cases where there was a large difference (large = noticeable) I found that my GH script was doing something wrong or bad, and fixing that resulted in a valid STL from Rhino.