Filament Length/Weight/Volume Estimator for 4d G-Code

by jag, published

Filament Length/Weight/Volume Estimator for 4d G-Code by jag Jan 5, 2012




Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

4323Views 824Downloads


This is a quick perl script to scan through a gcode file and figure out how much filament will be required.
It reads all of the "E" moves and adds them up each time they get reset to 0.
This will only work with absolute moves, not relative moves.

I did a 5 hour print and weighed it. The script said it should way 48.167 g. My kitchen scale said it weight 50 g.
Pretty good!


After downloading this script you may have to make it executable (chmod gou+x filament_length.pl)

To use it just pipe the gcode file through the perl script:

cat mygcodefile.gcode | ./filament_length.pl

(replace the ./ with whatever the path is to the script)

or, you can specify the file on the command line like this:

./filament_length.pl -f filename.gcode

you can also specify the density (in g/cc) and size of the filament (in mm)

./filament_length.pl -d 1.25 -s 2.75 -f filename.gcode

You can include or omit any of the command switches you like, it reads from stdin if you omit the filename and a density of 1.05 and diameter of 1.75 if you omit them.
The density of ABS is around 1.05 g/cc, PLA should be around 1.25 g/cc

It will produce a report like the following:

Cross sectional area of filament: 0.0240527984375 cm^2

macbookpro:~ jag$ ./filament_length.pl -d 1.25 -f ~/Dropbox/repg\ files/Dreidel03.gcode
Filament diameter is 1.75 mm
Filament density is 1.25 g/cc
Cross sectional area of filament: 0.0240527984375 cm^2

Total filament: 738.936 cm
Volume: 17.773 cc
Weight: 22.217 g

All Apps

Upgrade this Thing with Thingiverse Apps

No results.

Very nice! Works flawless for me. Thank you!

On my macbook I type the command line in the terminal but I get a message error:
macbook:Imp3D lionelmichaud$ cat rectangular_folding_case_Nylon.gcode | filament_length.pl
-bash: filament_length.pl: command not found

Any idea of the root cause ?

There are two possible things going on here. One, you may not be entering the whole path the to script. If it is a mac and you just clicked on it to download it, it is probably still in your download folder so, you could try cat rectangular_folding_case_Nylon.gcode | ~/Downloads/filament_length.pl

But, the script may not be executable which will cause you to get a "Permission Denied" error. To fix this, you can type chmod gou+x ~/Downloads/filament_length.pl (or whatever the path is).
This will make it executable so that the above should work.

Works great many thanks, was just what I was looking for

I need help please!! I'm on Windows, running the script from command line. I put all the gcode files and the script into C:/ and I write "C:/filament_length.pl -f 1.gcode" but I only get zeros in all the results. gcode generated with MakerWare. What am I doing wrong?

I haven't tried this script on windows or with gcode from makerware.
I'll try it out with makerware gcode when I get a chance. There might be something different about the gcode.

Can you share the .exe ? for those non coders :p

Perl isn't really a language that compiles to an executable. It's an interpreted script language. You just need to have a perl interpreter installed to run it.
Not being much of a windows users, I can't help you there.

Thanks, I'll give it a try. And let you know.

can this be used with gcode from any source, or Dimension printers' gcode only?

By dimension, I meant the dimension plugin to skein forge. I should probably change it to 4d gcode. It just has to be gcode that specifies X,Y,Z
amp; E in the G1 moves instead of setting the RPM for the extruder and doing moves with just X, Y and Z.