Welcome! Log In Create A New Profile

Advanced

add gcode before the starting Gcode of the slicer

Posted by amigob 
add gcode before the starting Gcode of the slicer
April 24, 2016 07:51AM
I made a preheating functionality, Measured at the center of the bed, that I need to start with a M703 Sxxx ( xxx is temperature )
I what to automatically add this at the real beginning of the gcode file.

When I now add it to the start gcode then it will be done after the extruders are heated up. that means that I end up with 2 blobs
of filament in the middle of my print bed ( dual extruder ).

The pre heating depends on the filament that is used ( PLA ABS etc ) so adding it to the printer start gcode doesn't work.

Is there a way to automatically add the M703 at the real beginning of the gcode file frim the slic3r software ?


P3steel DXL, with Due/RADDS/Raps128 dual Wade's extruder
Re: add gcode before the starting Gcode of the slicer
April 24, 2016 01:22PM
As the tooltip for start g-code says, if you put an M104 in your start g-code, it will do it when you insert it rather than inserting it where it feels like it.
Re: add gcode before the starting Gcode of the slicer
April 25, 2016 05:49AM
You can post-process the Gcode after it has been produced by Slic3r (Print Settings/Output options/Post-processing scripts.

Your script would output your M703 command, followed by all the Gcode that it gets from Slic3r.

Something like this (untested) Python code:

#!/usr/bin/perl -i
use strict;
use warnings;

my $temp = 123;

# Output the M567 line. Each colour proportion is output with 2 decimal places
printf "M703 S%4.0f\n", $temp;

# Go through the input file, line by line
while ( <> ) {
	# Print the existing line to the output
	print;
}

Re: add gcode before the starting Gcode of the slicer
April 25, 2016 07:12AM
Use variables rather than absolute values in your start G-code. e.g.

M140 S[first_layer_bed_temperature] ; Set bed temp
M116 ; Wait for bed temperature
T1 ; Select extruder 1
M104 S[temperature] ; Set extruder temp
M116 ; Wait for extruder temperature as well

Slic3r will replace the variables with the temperatures you have set when it generates the G-code, and will also not include its own temperature setting commands for the variables used in the start G-code

Dave
Re: add gcode before the starting Gcode of the slicer
April 25, 2016 08:04AM
dmould

I didn't have time yesterday to try it. But does this also work when I have a dual extruder setup where I don't always use both extruders?
Because you can have 2 different temperatures for the extruders.

The script suggestion of frankvdh will have no problem with that because the command will be just put in front of the output of slic3r.


P3steel DXL, with Due/RADDS/Raps128 dual Wade's extruder
Re: add gcode before the starting Gcode of the slicer
April 25, 2016 04:30PM
Example script didn't work because be for the while, the file is not opened
but this does the job
#!/usr/bin/perl -i
use strict;
use warnings;

my $temp = 95;

#only needed for windows
$^I = '.bak';

# Go through the input file, line by line
while ( <> ) 
{
    # for the first line add the M703
    if ($. == 1)
	{
	    printf "M703 S%4.0f\n", $temp 
	}
	# Print the existing line to the output
	print;
}
I make a number of these scripts, one for PLA, ABS, PETG


P3steel DXL, with Due/RADDS/Raps128 dual Wade's extruder
Re: add gcode before the starting Gcode of the slicer
April 26, 2016 07:14AM
Quote
amigob
dmould

I didn't have time yesterday to try it. But does this also work when I have a dual extruder setup where I don't always use both extruders?
Because you can have 2 different temperatures for the extruders.

The script suggestion of frankvdh will have no problem with that because the command will be just put in front of the output of slic3r.

Yes, just change the "T1" line to the extruder you want to use, or add another "T" and "M104" pair of commands to use both extruders (at different temperatures if desired).

The "Start" G-code is also placed in front of the print output of Slic3r, but unlike a script does not require any post-processing. In fact the very reason for the start G-code is to achieve exactly the sort of thing you want to do.

It is the code that I use because there is usually a need to heat the bed (which is slow) before heating the hotend, otherwise the plastic sits cooking in the nozzle while the bed is heating (which can take a long time) and in my experience that can result in chemical changes to the plastic that can block the nozzle. I also have a few lines at the end of my "start" G-code that moves the nozzle just off the edge of the bed, moves it down to bed height and wipes it across the edge of the bed just before starting the print, which results in any drooling plastic being wiped off.

Dave
Sorry, only registered users may post in this forum.

Click here to login