File: filament-weight.pl

package info (click to toggle)
slic3r 1.3.0%2Bdfsg1-5.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,552 kB
  • sloc: cpp: 63,126; perl: 21,512; ansic: 6,312; sh: 591; xml: 201; makefile: 37; python: 11
file content (31 lines) | stat: -rwxr-xr-x 915 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl -i
#
# Post-processing script for adding weight and cost of required
# filament to G-code output.

use strict;
use warnings;

# example densities, adjust according to filament specifications
use constant PLA_P => 1.25; # g/cm3
use constant ABS_P => 1.05; # g/cm3

# example costs, adjust according to filament prices
use constant PLA_PRICE => 0.05; # EUR/g
use constant ABS_PRICE => 0.02; # EUR/g
use constant CURRENCY => "EUR";

while (<>) {
    if (/^(;\s+filament\s+used\s+=\s.*\((\d+(?:\.\d+)?)cm3)\)/) {
        my $pla_weight = $2 * PLA_P;
        my $abs_weight = $2 * ABS_P;

        my $pla_costs = $pla_weight * PLA_PRICE;
        my $abs_costs = $abs_weight * ABS_PRICE;

        printf "%s or %.2fg PLA/%.2fg ABS)\n", $1, $pla_weight, $abs_weight;
        printf "; costs = %s %.2f (PLA), %s %.2f (ABS)\n", CURRENCY, $pla_costs, CURRENCY, $abs_costs;
    } else {
        print;
    }
}