filament-weight.pl 915 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/perl -i
  2. #
  3. # Post-processing script for adding weight and cost of required
  4. # filament to G-code output.
  5. use strict;
  6. use warnings;
  7. # example densities, adjust according to filament specifications
  8. use constant PLA_P => 1.25; # g/cm3
  9. use constant ABS_P => 1.05; # g/cm3
  10. # example costs, adjust according to filament prices
  11. use constant PLA_PRICE => 0.05; # EUR/g
  12. use constant ABS_PRICE => 0.02; # EUR/g
  13. use constant CURRENCY => "EUR";
  14. while (<>) {
  15. if (/^(;\s+filament\s+used\s+=\s.*\((\d+(?:\.\d+)?)cm3)\)/) {
  16. my $pla_weight = $2 * PLA_P;
  17. my $abs_weight = $2 * ABS_P;
  18. my $pla_costs = $pla_weight * PLA_PRICE;
  19. my $abs_costs = $abs_weight * ABS_PRICE;
  20. printf "%s or %.2fg PLA/%.2fg ABS)\n", $1, $pla_weight, $abs_weight;
  21. printf "; costs = %s %.2f (PLA), %s %.2f (ABS)\n", CURRENCY, $pla_costs, CURRENCY, $abs_costs;
  22. } else {
  23. print;
  24. }
  25. }