pyrech / gcode-estimator
Calculate filament length/weight/cost used in gcode file
Requires
- php: >=7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- symfony/phpunit-bridge: ^5.0
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:
- the
git tag
command - the releases page on Github
- the file listing the changes between versions
And finally some meta documentation:
Credits
License
GcodeEstimator is licensed under the MIT License - see the LICENSE file for details.