A popular, open source, 3D printing slicer software named Slic3r is written in Perl. I need to make a small change to the source code for a university project, but I'm completely unfamiliar with Perl.
Here's a nice image of what dual extrusion would look like. Essentially, when you change nozzles/materials, you create problems. You need a wipe tower to get rid of drool on the nozzles, and you must deal with reheating/cooling and other time-consuming tasks.
That's why all slicing programs I know of try to minimize extruder changes. For example, if layer 3 and layer 4 require both materials, then layer 3 will print extruder/material 1, then extruder/material 2. On layer 4, you will print extruder 2, then extruder 1.
However, I need to always print in the same order as the extruder numbers; every layer should start with extruder 1, then extruder 2, then 3, etc.
I believe I've found the important code snippet in the Slic3r source code. It is in lib/Slic3r/Print/GCode.pm, also on Github here, starting on line 622.
Here's the code:
# tweak extruder ordering to save toolchanges
my @extruders = sort { $a <=> $b } keys %by_extruder;
if (@extruders > 1) {
my $last_extruder_id = $self->_gcodegen->writer->extruder->id;
if (exists $by_extruder{$last_extruder_id}) {
@extruders = (
$last_extruder_id,
grep $_ != $last_extruder_id, @extruders,
);
}
}
I guess @extruders is just a list that can be [1], [1, 2], [1,2,3] or more. I would like to modify this block so that we always write the extruder commands in numerical order (1,2,3).
If you want more details about the Why?, I'd be glad to tell you more than you ever wanted to know about FFF printing, printed heat exchangers, and more.
EDIT In fact, commenting out the if statement worked perfectly. After recompiling, slic3r works just fine, and the Gcode appears to be correct. Therefore, I guess this is the only place in the software that the order is mentioned. The Slic3r code with this change is available on my fork at Github in case anybody ever runs into this same problem. Thank you, zdim, for the feedback!