GCodeToolbox
Version: 0.014 (ALPHA)
GCodeToolbox (gctoolbox) is a command-line perl-script to manipulate .gcode files (for 3D printers & RepRaps) as created by slicers (like Slic3r) from .stl files.
The main aim of this package is to be able to
- create various pieces (.gcode) with different settings (infill, infill-methods, extrude temperature etc) and
- then concatenate (cat) them for one print (yet untested), see for ABS & PLA Plate examples.
History
- 2013/03/17: 0.014: implementing support for relative position
- 2013/02/15: 0.013: filamentLength & Volume corrected
- 2013/02/14: 0.012: some bugfixes, and fine-tuning
- 2013/02/12: 0.011: render cmd implemented, renders .gcode to .png
- 2013/02/12: 0.010: rudimentary sequence 'concurrent' implemented (each slice per object) and default behaviour, --sequence=complete old behaviour
- 2013/02/11: 0.009: headX/Y/Z introduced, extruderDiameter abandoned
- 2013/02/11: 0.008: printerExtruderDiameter input, affects objectSpacing & slicer.skirt-distance (slic3r)
- 2013/02/10: 0.007: conf and fileList support
- 2013/02/09: 0.006: fanSpeed and temperature arguments possible, override gcode, proper filtering of object settings
- 2013/02/09: 0.005: proper header and trailer if objects are concated
- 2013/02/09: 0.004: proper movement at wrapping at concatenating (inserting G1 moves)
- 2013/02/09: 0.003: optional left-to-right to right-to-left swinging
- 2013/02/09: 0.002: passing slicer arguments via --slicer.[key]=[value]
- 2013/02/08: 0.001: start coding, first version, info and concat works
Installation
Install 2 perl-modules first:
% sudo apt-get install libgd-gd2-perl # this way
% sudo cpan GD # or so ...
% sudo cpan Device::SerialPort # not yet used, but required for future support of direct printing
and then
% make install
Usage
GCodeToolbox 0.013: gctoolbox [switches] [cmd] [file1]..[fileN]
info [file1]... provide info on .gcode files
slice [file1]... slice .stl files to .gcode
cat [file1]... concat multiple .gcode files to stdout
render [file1]... render multiple .gcode files to .png
-h or --help this help
-v or --verbose=v increase verbosity
--output=file output result (default: stdout)
--slicer=cmd define slicer (default: slic3r)
--slicer.[arg]=x define slicer arguments passed on slicer (e.g. --slicer.skirts=0)
--sequence=type define sequence type: { concurrent (default), complete }
--printer=file reference printer profile
--printerX=x define build width (default: 200) [mm]
--printerY=y define build depth (default: 200) [mm]
--printerZ=z define build height (default: 200) [mm]
--printerMargin=m define margin to perimeter of platform (default: 3) [mm]
--printerHeadX=x define head width (default: 16) [mm]
--printerHeadY=y define head depth (default: 16) [mm]
--printerHeadZ=z define head height (default: 50) [mm]
--cols=c define columns when concat(enating) (default none, auto-overflow) [mm]
--objectSpacing=x define distance between items when concat (default: 3) [mm]
--fanSpeed=s define fan-speed (s=0-255) (default none, defined in gcode)
--temperature=t define extruder temperature (default none, defined in gcode)
--conf=file configuration file, all command-line arguments (without '--'), one per line
--fileList=file file with list of files (one file per line)
--renderView=v define render view (default: top) { top, front }
Examples
Information of GCode
% gctoolbox info cube10mm.gcode
prints out some information about the actual gcode
Slicing STL to GCode
% gctoolbox slice cube10mm.stl
% gctoolbox --slicer=slic3r --slicer.skirt-distance=2 slice cube10mm.stl
creates cube10mm.gcode, default slicer is Slic3r, and arguments for the slicer can be given by --slicer.[arg]=[value].
% gctoolbox --slicer=anotherSlicer slice cube10mm.stl
use another slicer backend, it has to create .gcode
Concatenate
Concatenating (short 'cat', like the UNIX command 'cat') is the main feature of GCodeToolbox.
% gctoolbox cat cube10mm.gcode inchAxis.gcode > mixed.gcode
concatenate several gcode files into one gcode.

You can also define a multiplication:
% gctoolbox cat 10x cube10mm.gcode 3x inchAxis.gcode > mixed2.gcode
which concatenates 10 times cube10mm's and 3 times inchAxis's.
By default pieces are arranged left-to-right and when it overflows they are a placed further on the platform, but you can force wrapping:
% gctoolbox --cols=5 cat 25x cube10mm.gcode > 25cubes5x5.gcode
which is ideal when a grid of test objects with different settings are made (e.g. per row one temperature, per column certain settings like infill density).
% gctoolbox --fileList=myfiles.list cat > mixed3.gcode
whereas myfiles.list is
# my objects
cube10mm.gcode
cube10mm.gcode
inchAxis.gcode
inchAxis.gcode
steps5mm.gcode
steps5mm.gcode
Printer Definition
You can define a profile of your printer (default X=200, Y=200, Z=200 and margin=3), with e.g. "myprinter.conf":
# MyPrinter (all measurements in mm)
X = 150
Y = 180
Z = 120
margin = 3
headX = 20 # -- important to set to avoid collision when objects are concat(enat)ed
headY = 25 # dito
headZ = 50 # -- important, defines maxZ of an object to be printed in "complete object"-sequence (default)
defines the build-volume, margin of the built-platform toward the pieces, all variables of .conf file are also available via command-line --printer[key]=[value] as well ([key] starts with uppercase letter), for example:
% gctoolbox --printer=myprinter.conf cat 10x cube10mm.gcode > 10cubes.gcode
% gctoolbox --printerX=200 --printerY=180 --printerMargin=5 --printerHeadX=20 --printerHeadY=25 --objectSpacing=5 3x cube10mm.gcode > 3cubes.gcode
Sequences
There are two modes available (via --sequence=s) when concatenating:
- concurrent (default): a layer of all objects are printed together; hardware settings like temperature cannot be changed (would slow down printing immensely).
- complete: each object is printed complete before moving the next object, it allows to print objects with different temperatures (e.g. profiling printing material like PLA or ABS) like
these test plates (ABS & PLA), yet great care of possible collision of head toward already printed objects (see next section).
Since version 0.010 --sequence=concurrent is default, and --sequence=complete is available optionally (prior 0.010 --sequence=complete was default).
Collision Awareness
When using --sequence=complete the objects are printed individually complete first, which poses some danger that the extruder nozzle crashes into existing already printed items:
gctoolbox prints out a warning if these conditions are not met, and increases objectSpacing so there is no collision; important is to set the headX & headY properly.
By default headY = headX unless you define headY explicit as well. headZ defines the maximum objectZ to printed in this manner.
Render
You can render any .gcode to .png like this:
% gctoolbox render mixed.gcode
Tests
% make tests
and it will do some tests in tests/ and tests/array/; best explore the files.
Visualization
Best visit
- http://gcode.ws/
- http://www.buildlog.net/gview/ or
and simply drag&drop your .gcode file to the browser-window, and it will preview the gcode.
That's all for now,
Rene K. Mueller
initial 2013/02/08, update 2013/02/09