STL import script with some helpers

 From:  r2d3
8860.1 
Hi all,
i worked on a STL import script for MoI, and that is the result (for now...)
First i have to thank Karsten, Marco, Pilou and Michael for guiding the way!
Second to say: Its a stupid thing to import STL files into MoI because MoI is NURBS and STL is only Polygones!
But if you only have a STL file you can try to rebuild it to NURBS.
The script can help a little...

WARNING: IF YOU IMPORT BIG (>5mb) STL FILES IT CAN TAKE HOURS TO PROCESS AND IT CAN CRASH MOI!



This is what the script does:
1. reading the STL file, creating triangles and joining them to a solid (if possible..)
2. cleaning flat surfaces (removing all needless faces with a double boolean difference)
If your STL object only has flat surfaces -> YOU ARE DONE you will have a NURB object!
3. Redrawing curves and circles
Mostly your STL file will have curved or round surfaces. These will be converted to polylines in your STL file and the script helps you to redraw the polys to NURBS. In the end you will have nice outlines of the original STL object and you can rebuild it with the normal tools of MoI (Joining, Loft and Boolean operations).

SOME screenshots:

The imported Triangles as a solid:


Result after "Clean flat surfaces"


Select all polyline curves (no straight lines)


Choose if it should be a curve:


or a circle:

(Line is for a straight polyline which has more than two points. It will be converted to a 2 point line. Dont select this together with a curved polyline)

Result:


After some face deleting, joining, lofting:


and the final boolean difference you end up with a clean NURBS !


Use the script also for "Only Cleaning":


For every state of the import you find a object in the Objects folder:


HAVE FUN!

EDIT 23.03: added a binary STL Fault detection and putting the script files into a zip

EDITED: 23 Mar 2018 by R2D3