pyrech/gcode-estimator

Calculate filament length/weight/cost used in gcode file

v1.0.1 2020-02-23 15:06 UTC

This package is auto-updated.

Last update: 2024-10-30 01:53:49 UTC


README

GcodeEstimator is a PHP library to estimate the length/weight/cost of filament used for a 3D print through the corresponding gcode file.

Requires PHP >= 7.2.

Features

Unlike other implementations, this library supports most of g-code operations commonly used by 3d printers:

  • all kind of moves (rapid, linear, clockwise arc, counter-clockwise arc)
  • absolute and relative positionings
  • switch between absolute/relative modes
  • current position reset
  • millimeter and inche units

Estimations should be quite realist whatever the slicer/printer you use.

Installation

Use Composer to install GcodeEstimator in your project:

composer require "pyrech/gcode-estimator"

Usage

Basic usage to get the length of filament used:

include __DIR__.'/vendor/autoload.php';

use Pyrech\GcodeEstimator\Estimator;

$estimator = new Estimator();
$estimate = $estimator->estimate($absolutePathToGcode);

$estimate->getLength(); // returns the length of filament used (in mm);

You can also estimate the weight and cost of your print by describing the properties of your filament spool:

include __DIR__.'/vendor/autoload.php';

use Pyrech\GcodeEstimator\Estimator;
use Pyrech\GcodeEstimator\Filament;

$filament = new Filament(
    1.75, // filament diameter in mm
    1.24, // filament density in g/cm³
    750,  // weight of the spool in g
    25.99 // price of the spool (whatever your currency)
);

$estimator = new Estimator();
$estimate = $estimator->estimate($absolutePathToGcode, $filament);

$estimate->getLength(); // returns the length of filament used (in mm);
$estimate->getWeight(); // returns the weight of filament used (in g);
$estimate->getCost();   // returns the cost of filament used (in whatever currency you specified);

Further documentation

You can see the current and past versions using one of the following:

And finally some meta documentation:

Credits

License

GcodeEstimator is licensed under the MIT License - see the LICENSE file for details.