Skip to content

About

Makes STL to Step Files

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

STL → STEP converter

Turn STL meshes into STEP solids with real curved surfaces, not piles of triangles.

Same part rotating: the STL mesh with every triangle edge visible on the left, the converted STEP with 12 smooth faces on the right

Real output on examples/sample_part.stl: 10,226 triangles become 12 faces.

Python OpenCascade Platforms

An STL file is only triangles, so a round hole is a many-sided polygon and a CAD program shows every edge as a mesh line. This tool finds the holes, bosses, round bars, cones, domes and rounded edges in the mesh and rebuilds them as true curved CAD surfaces with exact circular edges. It repairs small mesh problems first so you get a solid, and it comes with a local web dashboard. On Windows with SolidWorks it can also save a .SLDPRT.

Heads-up: freeform / organic surfaces (sculpted shapes, scans) are not smoothed. They stay as flat triangles, because that needs NURBS fitting. See Limitations.

Jump to: Quick start · How it works · Mesh repair · Dashboard · Options · SolidWorks · Cloud / GitHub · Results · Limitations · Troubleshooting


Quick start

Terminal: pip install, convert the sample part, start the dashboard

Terminal drawing; the converter log shown is real output.

You need Python 3.9 to 3.12 (tested on 3.12; the Docker, Codespaces and Actions setups use 3.11).

git clone https://github.com/YOUR-NAME/stl-to-step.git
cd stl-to-step
pip install -r requirements.txt

python stl2step.py examples/sample_part.stl     # try the included sample, writes examples/sample_part.step
python dashboard.py                             # or open the dashboard: http://localhost:8000

On Windows you can double-click start_dashboard.bat: it checks Python, installs the libraries and starts the dashboard.

More ways to run it:

python stl2step.py part.stl                  # writes part.step next to it
python stl2step.py *.stl -o out_folder       # batch
python stl2step.py part.scad                 # OpenSCAD file (needs OpenSCAD installed)

requirements.txt installs numpy, cadquery-ocp (OpenCascade for Python) and, on Windows only, pywin32 (only for the SolidWorks option). Without numpy / cadquery-ocp the script still runs in a basic pure-Python mode that merges flat areas but leaves curves as triangles.


How it works

Five steps animated on the sample part: read the STL, find curved surfaces, merge flat triangles, rebuild exact edges, sew into a STEP solid

Each frame is rendered from the converter's real output on the sample part.

  1. Read the STL (binary or ASCII) and weld duplicate vertices.
  2. Repair the mesh: consistent triangle orientation and closed gaps (next section).
  3. Find curved surfaces. A systematic search with robust fitting finds cylinders first, then rounded edges (tori around those cylinders' axes), cones and spheres. Each candidate grows over the mesh while the triangles stay within tolerance, and borders between tangent surfaces are cleaned up.
  4. Merge flat triangles into planar faces.
  5. Rebuild exact edges: straight lines and true circles (short polylines only where neither fits).
  6. Build the solid with OpenCascade: faces on the fitted surfaces, checked for validity and area, then sewn together.
  7. Verify the volume against the mesh and write the STEP. If a face cannot be built exactly, only that face falls back to flat facets.

Why holes come out round

A 16-sided polygon (the mesh) gets replaced by one exact circle

Simplified to 16 vertices for the drawing; the fit uses all the real vertices of the sample's hole.

The mesh vertices of a hole all lie on one circle, so a least-squares fit recovers the exact radius and the polygon becomes a single circular edge. The same idea, with different surface types, finds cones, spheres and rounded edges.


Mesh repair

Damaged mesh with a gap (red edges) and flipped triangles (purple), then the repaired closed solid with the new triangles in green

Damage added to the sample on purpose, repaired by the real repair_tris function.

A STEP solid needs a closed mesh with every triangle facing outward. Repair runs by default and:

  • turns flipped triangles back the right way,
  • closes gaps (ear clipping, with a fan fallback),
  • flips the whole mesh if it was inside out.

Without it, a mesh with a gap can only become a surface. Repair is meant for small gaps. It fills every opening it finds, so if a whole face is missing, any through-holes in that face get capped too. Turn it off with --no-repair.


The dashboard

Dashboard walkthrough: drop an STL, convert, see results, enlarge the auto-rotating preview, switch to dark mode

Drawn illustration of the layout (simplified), not a screen recording.

python dashboard.py starts a local web page. Everything runs on your computer; results are saved in dashboard_output/.

  1. Upload: drop an STL on the page.
  2. Output: the dashboard creates a STEP file. To create a SolidWorks .SLDPRT, use the command-line option described in SolidWorks .SLDPRT on a Windows PC with SolidWorks installed.
  3. Settings: recover curved surfaces, repair mesh first, smoothing level, fit tolerance, angle tolerance, minimum triangles.
  4. Convert, then read the result: triangles in, faces out, curved surfaces found, Faceted area, Volume match, a face-type bar, the log and download buttons. Earlier conversions stay in History.

Preview: drag to rotate. Click Enlarge (or double-click the preview) for a big view that auto-rotates; Esc or a click outside closes it. Auto-rotate has a checkbox, and starts off if your system asks for reduced motion. Themes: Light / Dark / Auto.

Faceted area is the share of the surface still made of small flat faces. Under 1% means almost no mesh lines will show in CAD.

Settings explained
Setting Default What it does
Smoothing level Exact Presets for the two values below. Higher merges more small triangles into bigger faces: fewer mesh lines, slightly less exact.
Fit tolerance 0.0005 Fraction of the part size a surface may deviate. Raise it for noisy or scanned meshes.
Angle tolerance 8° Largest surface-normal error allowed for a curved fit.
Min triangles 10 Smallest group of triangles that may become a curved surface.
Repair mesh first on Fixes flipped triangles and closes gaps.

Command line options

python stl2step.py INPUT [INPUT ...] [options]

  -o, --out FOLDER      output folder (default: next to each input)
  --sldprt              also save a SolidWorks .SLDPRT (Windows + SolidWorks + pywin32)
  --no-curves           skip curved-surface recovery (flat merged faces only)
  --tol FRACTION        fit tolerance as a fraction of part size   (default 0.0005)
  --ang DEGREES         normal tolerance for curved fits            (default 8)
  --min-tris N          minimum triangles per curved surface        (default 10)
  --angle DEGREES       max angle to merge neighbouring flat triangles (default 3)
  --no-repair           do not close gaps / fix flipped triangles
  --no-merge            keep every flat triangle as its own face

Noisy or scanned mesh? Try --tol 0.003 --ang 15.


SolidWorks .SLDPRT

.SLDPRT is a closed SolidWorks format, so only SolidWorks can write it. step2sldprt.py drives SolidWorks on your PC: it opens the STEP and saves it as .SLDPRT.

pip install pywin32
python step2sldprt.py part.step
python stl2step.py part.stl --sldprt        # convert and save the part in one go

Needs Windows with SolidWorks installed and licensed. If it does not work, open the STEP in SolidWorks (File → Open → STEP, Options → Solid/Surface geometry, tick Try Form Solid) and use Save As.

This part has not been tested against a real SolidWorks install by the author. The STEP output itself is tested.


Run it from anywhere

A. GitHub Codespaces (any browser)

Code → Codespaces → Create codespace. The dashboard starts on port 8000 (open the Ports tab if no tab opens). The dashboard exports STEP files in Codespaces too. Use the command line on a Windows PC with SolidWorks for .SLDPRT output.

B. GitHub Actions (no install)

Put STL files in input/ and commit (this works from the GitHub website, also on a phone). The Convert STL to STEP workflow converts them and uploads a step-files artifact you can download from the run. You can also start it from the Actions tab.

C. Always-on hosting (Render, Railway, Fly.io, ...)

GitHub itself cannot run a live web app. Deploy the included Dockerfile to a host and set:

Variable Meaning
DASH_PASSWORD Password for the dashboard (HTTP Basic login, any user name). Strongly recommended on any public address.
MAX_UPLOAD_MB Largest upload in MB (default 200).
HOST, PORT Listen address and port (the Dockerfile sets 0.0.0.0 and 8000).
NO_BROWSER Set to 1 to stop it opening a browser.

Keep the repo private if your parts are confidential.

The Codespaces, Actions and Docker files are provided as configuration. The converter and the dashboard (including password mode) were tested locally; the cloud setups themselves have not been run by the author.


Results

Tested on parts modelled in CAD, exported to STL, converted back, and compared with the original solid.

Test part Faces out Volume (STEP vs original)
Block, 2 holes, countersink, round boss with rounded top edge (examples/sample_part.stl, 10,226 triangles) 12 (3 cylinders, 1 rounded edge, 1 cone, 7 flat) 62677.22 vs 62677.38; 0 of 6000 test points differ
Block with a through hole and a rounded corner 8 46274.69 vs 46274.69
Block, round boss and a sphere dome 9 27939.56 vs 27939.56
Round bar with a cross hole 4 11581.67 vs 11581.59
Block with an angled hole 7 46243.97 vs 46243.80
Block with 4 holes (20,000 triangles) 10 43978.76 vs 43978.76

Meshes with randomly flipped triangles or small gaps are repaired and match the clean file. A mesh of about 10,000 triangles takes a few seconds up to about 10 s; larger meshes take longer. These are synthetic CAD parts; real-world files, especially scans, vary.


Limitations

  • Freeform / organic surfaces stay faceted. Check Faceted area. If it stays high, those areas need a NURBS tool, for example Fusion 360 Convert Mesh → Organic, SolidWorks Scan to 3D → Surface Wizard, or Rhino QuadRemesh + ToNURBS.
  • Noisy / scanned meshes: curved fits get unreliable; raise --tol and --ang.
  • Very coarse meshes: small surfaces made of only a few triangles (for example a countersink cone with a dozen facets) can stay as flat facets.
  • Rounded edges (tori) are only recognised around the axis of a hole, boss or bar that was found first.
  • Repair fills every gap, including the openings of through-holes if a whole face is missing. It is meant for small gaps.
  • Dashboard takes STL only. For .scad, use the command line.
  • The .SLDPRT route needs SolidWorks on Windows and is untested by the author.

Troubleshooting

Common problems
Problem Try
pip install cadquery-ocp fails Use Python 3.11 or 3.12; run python -m pip install numpy cadquery-ocp.
Output has many flat faces Check Faceted area. For scans try Smoothing level Medium or High.
Output is a surface, not a solid Leave Repair mesh first on. If it still warns, repair the STL in Meshmixer or 3D Builder.
Dashboard does not open Go to http://localhost:8000 yourself. If the port is busy it uses the next free one (see the terminal).
--sldprt says "This server cannot run SolidWorks" Run the command on a Windows PC with SolidWorks installed. If needed, install pywin32 with python -m pip install pywin32; alternatively create the STEP in the dashboard and run python step2sldprt.py file.step on that PC.

Project layout

stl2step.py          converter (command line + library)
dashboard.py         local web dashboard
step2sldprt.py       STEP → SolidWorks .SLDPRT (via the SolidWorks API)
sw_bridge.py         local SolidWorks bridge for hosted dashboards
start_bridge.bat     one-click launcher for the bridge (Windows)
start_dashboard.bat  one-click launcher for Windows
requirements.txt     numpy, cadquery-ocp, pywin32 (Windows)
Dockerfile           for hosting the dashboard
examples/            sample_part.stl, the part used in the animations
docs/                the animations and make_gifs.py (regenerates them)
input/               drop STL files here for the GitHub Action
.github/workflows/   Action: convert everything in input/
.devcontainer/       Codespaces setup
Regenerate the animations

The mesh, detected surfaces, repair and numbers in the GIFs come from running the real converter on examples/sample_part.stl. The dashboard and terminal GIFs are drawn illustrations.

pip install numpy cadquery-ocp pillow
python docs/make_gifs.py        # about a minute, rewrites docs/*.gif

License

Add a LICENSE file before publishing. The libraries used keep their own licenses (numpy, cadquery-ocp / OpenCascade, pywin32, Pillow for the animations).

About

Makes STL to Step Files

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages