A guide to slicing STL files using CuraEngine CLI, based on real-world troubleshooting.
CuraEngine is bundled inside the Cura application:
# macOS
/Applications/UltiMaker\ Cura.app/Contents/Resources/CuraEngine
# Linux (typical locations)
/usr/share/cura/CuraEngine
# or
/opt/cura/CuraEngine
# Windows
C:\Program Files\Ultimaker Cura\CuraEngine.exeCuraEngine slice \
-d <definition_search_paths> \
-j <machine_definition.json> \
-e0 -j <extruder_definition.json> \
-s <setting>=<value> \
-l <input.stl> \
-o <output.gcode>CuraEngine 5.x has many undocumented required settings. Without these, you'll get errors like:
[error] Trying to retrieve setting with no value given: roofing_layer_count
Here's a working minimal set:
CURA_ENGINE="/Applications/UltiMaker Cura.app/Contents/Resources/CuraEngine"
DEFS_PATH="/Applications/UltiMaker Cura.app/Contents/Resources/share/cura/resources/definitions"
EXTRUDER_DEFS="/Applications/UltiMaker Cura.app/Contents/Resources/share/cura/resources/extruders"
"$CURA_ENGINE" slice \
-d "$DEFS_PATH:$EXTRUDER_DEFS" \
-j "$DEFS_PATH/fdmprinter.def.json" \
-e0 -j "$DEFS_PATH/fdmextruder.def.json" \
-s center_object=true \
-s mesh_position_x=60 \
-s mesh_position_y=60 \
-s layer_height=0.2 \
-s infill_sparse_density=20 \
-s support_enable=true \
-s support_type=buildplate \
-s adhesion_type=brim \
-s material_print_temperature=200 \
-s material_bed_temperature=60 \
-s roofing_layer_count=1 \
-s flooring_layer_count=1 \
-s top_layers=4 \
-s bottom_layers=4 \
-s wall_line_count=2 \
-s machine_width=220 \
-s machine_depth=220 \
-s machine_height=250 \
-s material_diameter=1.75 \
-s support_z_seam_away_from_model=1 \
-s support_z_seam_min_distance=1.0 \
-s lightning_infill_support_angle=40 \
-s scarf_joint_seam_end_height_ratio=0 \
-s reset_flow_duration=2.0 \
-l model.stl \
-o output.gcodeProblem: By default, models may be placed at their original coordinates, often far outside the build area.
Solution: Use these settings together:
-s center_object=true \
-s machine_center_is_zero=false \
-s mesh_position_x=60 \
-s mesh_position_y=60The mesh_position_x/y values offset the centered model. For a 220x220 bed:
- Models get centered around (50, 50) by default
- Adding 60mm offset moves them to ~(110, 110) = true center
Adjust based on your bed size: offset = (bed_size / 2) - 50
| Setting | Description | Example |
|---|---|---|
layer_height |
Layer height in mm | 0.2 |
infill_sparse_density |
Infill percentage | 20 (20%) |
support_enable |
Enable supports | true |
support_type |
Support placement | buildplate or everywhere |
adhesion_type |
Bed adhesion type | brim, raft, skirt, none |
material_print_temperature |
Nozzle temp °C | 200 |
material_bed_temperature |
Bed temp °C | 60 |
material_diameter |
Filament diameter mm | 1.75 |
wall_line_count |
Number of perimeters | 2 |
top_layers |
Solid top layers | 4 |
bottom_layers |
Solid bottom layers | 4 |
#!/bin/bash
# slice_all.sh - Batch slice STL files
CURA_ENGINE="/Applications/UltiMaker Cura.app/Contents/Resources/CuraEngine"
DEFS_PATH="/Applications/UltiMaker Cura.app/Contents/Resources/share/cura/resources/definitions"
EXTRUDER_DEFS="/Applications/UltiMaker Cura.app/Contents/Resources/share/cura/resources/extruders"
STL_DIR="${1:-.}"
OUT_DIR="${2:-./gcode}"
mkdir -p "$OUT_DIR"
for stl in "$STL_DIR"/*.stl; do
filename=$(basename "$stl" .stl)
echo "Slicing: $filename"
"$CURA_ENGINE" slice \
-d "$DEFS_PATH:$EXTRUDER_DEFS" \
-j "$DEFS_PATH/fdmprinter.def.json" \
-e0 -j "$DEFS_PATH/fdmextruder.def.json" \
-s center_object=true \
-s mesh_position_x=60 \
-s mesh_position_y=60 \
-s layer_height=0.2 \
-s infill_sparse_density=20 \
-s support_enable=true \
-s support_type=buildplate \
-s adhesion_type=brim \
-s material_print_temperature=200 \
-s material_bed_temperature=60 \
-s roofing_layer_count=1 \
-s flooring_layer_count=1 \
-s top_layers=4 \
-s bottom_layers=4 \
-s wall_line_count=2 \
-s machine_width=220 \
-s machine_depth=220 \
-s machine_height=250 \
-s material_diameter=1.75 \
-s support_z_seam_away_from_model=1 \
-s support_z_seam_min_distance=1.0 \
-s lightning_infill_support_angle=40 \
-s scarf_joint_seam_end_height_ratio=0 \
-s reset_flow_duration=2.0 \
-l "$stl" \
-o "$OUT_DIR/$filename.gcode" 2>&1 | grep -E "(Print time|error)"
if [ -f "$OUT_DIR/$filename.gcode" ]; then
echo "✓ Created: $filename.gcode"
else
echo "✗ Failed: $filename"
fi
done
echo "Done! G-code files in: $OUT_DIR"Usage:
chmod +x slice_all.sh
./slice_all.sh /path/to/stl/files /path/to/outputAdd the missing setting with a sensible default. Common culprits:
roofing_layer_count=1flooring_layer_count=1support_z_seam_away_from_model=1reset_flow_duration=2.0lightning_infill_support_angle=40scarf_joint_seam_end_height_ratio=0
Check your G-code for coordinates beyond your bed size:
grep "^G[01].*X.*Y" output.gcode | head -20If coordinates are wrong, ensure you have:
-s center_object=true
-s mesh_position_x=60 # Adjust for your bed
-s mesh_position_y=60The slicer crashed mid-process. Check stderr for the specific missing setting and add it.
Instead of fdmprinter.def.json, you can use a specific printer definition:
ls "$DEFS_PATH" | grep -i ender # Find your printer
# creality_ender3.def.json, etc.Note: Printer definitions inherit from base definitions and may still require the same additional settings.
- CuraEngine GitHub
- Cura Settings Documentation
- Print3r - Alternative CLI wrapper for multiple slicers
Man, thank you for this - I wasted two full days fighting those “roofing_layer_count” errors until I stumbled into something similar. Your breakdown of the centering math alone would have saved me six hours of printing air. What really clicked for me was realizing the CLI isn’t broken, just painfully literal about defaults the GUI hides. After getting a working batch script from your post, I started slicing whole folders at once, which led me to https://www.gambody.com/ while looking for game-accurate test models—ended up buying a Destiny hand cannon STL and ran it through your exact settings. The gun came out perfect because the mesh was clean and the offset formula matched my 235mm bed. So my advice: save this guide as a template, keep a text file with your machine dimensions, and always test with a 20mm cube before burning filament on a 12-hour print. CuraEngine is brutally fast once you feed it the right JSONs.