Verified recipe
Current top level object is not a 3D object.
TL;DR
openscad --backend=Manifold --export-format=binstl -o model.stl model.scad
python3 check_stl.py model.stl
Problem
Headless STL export fails when the top-level value of the .scad file is not a 3D solid. square(), circle(), polygon(), text(), projection(), and an imported SVG or DXF are 2D. OpenSCAD then prints Current top level object is not a 3D object. and returns exit code 1. Current top level object is empty. is the same gate for a model that produced no geometry.
A second, separate failure shows up on the CGAL Nef backend: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation!. Degenerate booleans and zero-area contact (two solids that share only an edge) trip it. The GUI and the CLI also disagree about STL type: the GUI writes binary STL, and the CLI defaults to ASCII. A pipeline that assumes a compact binary file will mis-read an ASCII export even when the geometry is fine.
The check below proves the file is a non-empty binary STL with a consistent triangle table. It does not prove the mesh is manifold.
Environment
- OS
- Linux CI image
- OpenSCAD
development snapshot 2025.08.17 or newer- Python
3.11 or newer, standard library only
OpenSCAD 2021.01, still the build many distro packages ship, has no --backend flag. On that release, drop the flag and repair the geometry until the CGAL backend accepts it. The 3D-object error and the STL size check are the same.
Steps
Confirm the script evaluates to one 3D solid. Give 2D geometry thickness instead of exporting it as STL:
linear_extrude(height = 2) square([10, 10]);
Export from CI with -o so OpenSCAD does not open a window. Pass the backend and the container format explicitly. On snapshots that advertise --backend in openscad --help (the 2025.08.17 nightly does; current master marks Manifold as the default), Manifold avoids the Nef assertion:
openscad --backend=Manifold --export-format=binstl -o model.stl model.scad
echo "exit:$?"
--export-format=binstl matters because the CLI STL default is ASCII, and that default is expected to change. Scripts that need ASCII should pass --export-format=asciistl rather than relying on the default.
If two cubes only share an edge, the result is non-manifold and CGAL often asserts. Face contact is valid. Edge contact is not. Overlap the pair by a small positive amount instead of placing them so they touch on a line:
cube(10);
translate([9.99, 0, 0]) cube(10);
translate([10, 10, 0]) cube(10) next to cube(10) shares only an edge. Do not treat a zero exit from a GUI preview as proof the CLI export worked.
Save this as check_stl.py and run it on the file you just wrote. Binary STL is an 80-byte header, a little-endian uint32 triangle count, then 50 bytes per triangle:
import pathlib, struct, sys
path = pathlib.Path(sys.argv[1])
data = path.read_bytes()
if len(data) < 84:
sys.exit(f"{path} is too small to be a binary STL ({len(data)} bytes)")
count = struct.unpack_from("<I", data, 80)[0]
expected = 84 + count * 50
if len(data) != expected:
sys.exit(f"{path} size {len(data)} != 84 + {count} * 50")
if count == 0:
sys.exit(f"{path} has zero triangles")
print(f"ok {path} triangles={count} bytes={len(data)}")
On OpenSCAD 2021.01, omit --backend=Manifold (the process will exit with an unknown-argument error) and keep --export-format=binstl only if that build's --help lists it. The geometry still has to be a 3D solid.
Verification
A good export exits 0 and the checker prints a line that starts with ok .
openscad --backend=Manifold --export-format=binstl -o model.stl model.scad
python3 check_stl.py model.stl
ok model.stl triangles=N bytes=M means the byte length matches the triangle table and N is greater than zero. ASCII STL fails this check on purpose. An empty file, a truncated file, or exit code 1 with Current top level object is not a 3D object. means the export did not produce a mesh. This script does not measure manifoldness. If a slicer still rejects the file, the solids are intersecting in a non-manifold way and need a positive overlap, which is a geometry fix, not a different exporter flag.
Exact error strings
Current top level object is not a 3D object.Current top level object is empty.ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation!