5

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!

  • I appreciate your detailed explanation about "extruders" but it's not clear to me what you need to do with that code. The `@extruders` contains the keys of `%by_extruder` which _are sorted_ so `(1,2,..)` order (of keys) is there already. This is modified by moving that one particular `$last_extruder_id` to the front of `@extruders` (if it exists). So what do you need to do to this? – zdim Aug 16 '17 at 20:48
  • I wasn't sure if the extruder list is already always sorted. If that's the case, then I guess I can just remove the whole _if_ statement and that's the solution? I want to always print (1,2,3), and never (2,1,3), (3,2,1), or (3,1,2). – pedro pablo león jaramillo Aug 16 '17 at 20:52
  • Ah, OK. The `sort { ... } LIST` applies the criterion in curlies to pairs of elements of `LIST` in succession. The elements are available as `$a` and `$b`. So `sort { $a <=> $b } LIST` says to sort the `LIST` by comparing elements numerically (the `<=>` operator). (This is a bit simplified and in a slightly imprecise language.) So yes, `@extruders` contains a list of numbers that have been sorted numerically. This presumes that the keys being sorted are indeed plain numbers. Then the `if` statement moves that one to front. So yes, get rid of it if you don't want that. – zdim Aug 16 '17 at 20:55
  • 1
    Ok, that makes sense. I will try to rebuild the software and hope there aren't other places that need a change, and that I haven't broken anything. – pedro pablo león jaramillo Aug 16 '17 at 20:58
  • 1
    In general, slicing and path layout are quiet complex. In a dual headed print even more so. Odds are the existing implementation already does a very good job at head management. You are better off telling your slicer to build a tower, and wipe between layers. https://3dprinting.stackexchange.com is also available. – EvilTeach Aug 16 '17 at 21:01
  • I'm actually using only one extruder, but I merge several STL files, and assign a different extruder to each one. I can set the offset to zero and remove the tool changes. That way, I can control the print settings in different areas of a part. This is important for some tiny, delicate shapes that I'm trying to produce. – pedro pablo león jaramillo Aug 16 '17 at 21:09

0 Answers0