Skip to content

Instantly share code, notes, and snippets.

@JacobFV
Created December 12, 2025 16:48
Show Gist options
  • Select an option

  • Save JacobFV/3bcc83a2c6cc77f2b7eb6ed5c8f1ebaa to your computer and use it in GitHub Desktop.

Select an option

Save JacobFV/3bcc83a2c6cc77f2b7eb6ed5c8f1ebaa to your computer and use it in GitHub Desktop.
Guide to 3D printing from the command line with CuraEngine CLI

3D Printing from the Command Line with CuraEngine

A guide to slicing STL files using CuraEngine CLI, based on real-world troubleshooting.

Finding CuraEngine

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.exe

Basic Command Structure

CuraEngine slice \
  -d <definition_search_paths> \
  -j <machine_definition.json> \
  -e0 -j <extruder_definition.json> \
  -s <setting>=<value> \
  -l <input.stl> \
  -o <output.gcode>

Required Settings (CuraEngine 5.x)

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.gcode

Centering Models on the Build Plate

Problem: 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=60

The 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

Common Settings Reference

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

Batch Slicing Script

#!/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/output

Troubleshooting

"Trying to retrieve setting with no value given"

Add the missing setting with a sensible default. Common culprits:

  • roofing_layer_count=1
  • flooring_layer_count=1
  • support_z_seam_away_from_model=1
  • reset_flow_duration=2.0
  • lightning_infill_support_angle=40
  • scarf_joint_seam_end_height_ratio=0

Model coordinates outside build area

Check your G-code for coordinates beyond your bed size:

grep "^G[01].*X.*Y" output.gcode | head -20

If coordinates are wrong, ensure you have:

-s center_object=true
-s mesh_position_x=60  # Adjust for your bed
-s mesh_position_y=60

G-code file is tiny/incomplete

The slicer crashed mid-process. Check stderr for the specific missing setting and add it.

Alternative: Using Printer-Specific Definitions

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.

Resources

@billy00xv-sudo

billy00xv-sudo commented May 6, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment