How to generate gcode only for first layer?

  • As first layer is so important, I am looking for an easy way to generate the gcode to print just the first layer.
    I see that with Slic3r you can cut from a Z
    But for test purposes I prefer just selecting a number of layers to be generated so I can easily generate different "first layer(s) tests" with different first layer(s) settings (width, height, speed, flow....)
    The only way I achieve it is editing the gcode.
    Any help?
    Thanks


    Are you doing this to set Z-height, bed levelling, etc., or do you have reasons to evaluate the first layer for each particular object being printed?

  • mac

    mac Correct answer

    4 years ago

    I understand your question like this:




    I know I could cut the mesh and just slice the bottom of my model, but since I am interested in a given number of layers and the heigh of a layer may change according to settings (e.g.: 0.2mm, 0.1mm, 0.05mm...), I want to find a way to generate an arbitrary number of layers from the full model. I use slic3r.




    If my understanding is correct, then you can achieve what you want with a few steps.



    Use verbose GCODE



    The setting is under "Print settings → Output Options". This will output gcode with comments in it.



    Save the finishing gcode of a valid printing job



    Basically, open a valid gcode file, and save the last few lines (comments will help you to understand which ones, it changes from printer to printer) in a separate file (gcode.tail). These lines are typically those that move away the nozzle from the print, disable the heating element, the steppers and the part cooling fan.



    Prepare the first-lines.sh script



    #! /usr/bin/env sh
    sed -e '/move to next layer (3)/,$d' $1 > /tmp/gcode.tmp
    echo ~/gcode.tail >> /tmp/gcode.tmp
    echo /tmp/gcode.tmp


    What this script does is:




    • take a file name from the command line ($1) and savie into gcode.tmp only the part of it up to and excluding the line saying "move to the next layer (3)" (you should actually use the number of layers you actually want here, 3 is just an example). Again, the presence of such a line depends from you generating "verbose gcode".

    • append to gcode.tmp the content of the file gcode.tail (here replace ~/ with the actual path on your machine.

    • output as a stream the full content of gcode.tmp



    Set your printer to automatically run the script onto the generated gcode



    This setting is again under "Print settings → Output Options". You have to type in the full path to first-lines.sh. Also remember to make the script executable (chmod +x first-lines.sh).



    You can also hover over the textbox to get additional information of how you can access slic3r variables there (for example you may want to read the layer height from the settings and compute within the script the number of layers you want to keep).



    Profit



    :)



    Final notes:




    • I tried the sed command and have post-processing scripts running on my gcode myself, so it should work, but I haven't tried the full procedure myself, if you encounter bugs please leave a comment so I can fix the answer for everybody. :)

    • I use slic3r Prusa Edition (I believe these settings are the same, but just in case... you may wish to download that version.

    • All of the above should work out-of-the-box on all mainstream Linux distributions and OSX. For windows, it has been suggested in the comments to install CygWin.

    • Since this procedure still slices the full model and then throw away most of it, you could make it faster by only slicing a reasonably thick "bottom part" of your model. For example: say that you know you will never want to print more than 5 layers and never with a layer height past 0.3mm... in this case you could only keep the bottom 2mm of your model and you'd be safe for all other combinations of layers and layer heights. Don't keep exactly 1.5mm though, as this is likely to generate a different top layer than the one in the full model.



    Good luck! :)


    Thanks mac. I got an easy workaround as well from the Slic3r Github. The suggested solution is quite straight forward: Just adding a small Perl script as postprocessing that drops all gcode of layers not to be printed.

    That's pretty much the same suggestion than mine, just slower (as it parses the full file rather than splicing it. :) (and less readable because is perl ;) )

    OSX uses bash by default in Terminal; for Windows I recommend installing CygWin.

    @CarlWitthoft - Thanks, added in the main body of the answer.

    @LuisRosety - Since you solved the issue with this method (post-processing of the gcode via slic3r settings), consider either approving this answer or writing your own and approving that instead, so that others will have a clear indication this problem has a solution. :)

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used