Speed up gcode analysis

This OctoPrint plugin uses a generated metadata comment in the gcode file to speed up the analyzing process on systems with limited resources like the Raspberry PI.

As an example: Analyzing a 7MB gcode file on my Raspberry PI B+ took ~17min. With included metadata only 2s while generating the metadata itself took additional 8s on my laptop.

How it works

The separate analysis script uses OctoPrint’s gcode interpreter to analyze the given gcode file. After the analysis has finished the metadata is written to the beginning of the file.

If the gcode is uploaded the plugin stops the gcode analysis started by OctoPrint and looks whether the file contains such metadata or not. If metadata is found it will be added to the .metadata.yaml and the METADATA_ANALYSIS_FINISHED event will be fired. Otherwise the file will be analyzed by OctoPrint as usual by adding it to the analysis queue again.

Installation of the analysis script

This is a guide how I set it up for Slic3r. If your slicer doesn’t support post-processing scripts you need to run the analysis manually.

$ mkdir -p ~/.Slic3r/utils/gcode_metadata
$ cd ~/.Slic3r/utils/gcode_metadata
$ wget https://github.com/malnvenshorn/OctoPrint-MetadataPreprocessor/archive/master.zip
$ unzip -j master.zip "OctoPrint-MetadataPreprocessor-master/analysis/*" -d .
$ virtualenv -p /usr/bin/python2 venv
$ source venv/bin/activate
$ python setup.py install


$ analysis --help
Usage: analysis [OPTIONS] PATH

  --speed-x FLOAT
  --speed-y FLOAT
  --offset <FLOAT FLOAT>...
  --max-t INTEGER
  --help                     Show this message and exit.


You can easily integrate the analysis script in your workflow with slic3r. Simply add the absolute path of the script under the post-processing scripts option.


If you want to supply arguments, e.g. --g90-extruder, you need to write a wrapper script. I placed mine under ~/.Slic3r/utils/gcode_metadata/generate_octoprint_metadata.sh, see screenshot above.


~/scripts/gcode_metadata/venv/bin/analysis --g90-extruder "$@"