User avatar
KeyboardWarrior
Posts: 480
Joined: Thu Jun 19, 2014 5:02 pm

Tip of the Day 8- Scripts tab, G-Code

Introduction:

The scripts tab is a really powerful tool in the FFF settings window. This allows you to set Starting Scripts, set G-Code for every Tool Change, set G-Code for every Layer Change and set G-Code for the end of your print!

If you're intimidated by G-Code, it's actually a lot easier than it looks, a great way of learning and testing is to use the Communications tab over USB connection and send your printer a line of G-Code at a time to see the responses. One thing to keep in mind is that different printers will accept different commands to accomplish the same task. This is just something you should keep in mind if your wondering why a certain G-Code command does not work with your printer.

Basics of G-Code:

G-Code is read line by line, the printer will accomplish one line of G-Code, then move on to the next. Always capitalize the letters in G-Code, spacing is important, and anything that comes after a semi-colon will not be read on that line. The two lines below are for home-all, and then move to 100, 100, 100 at a certain speed. The printer will home all 3 axis, then once that is done, move to the next line of G-Code.

G28; home all axis
G1 X100 Y100 Z100 F3600; Move to X100, Y100, Z100 at 3600 mm/min
(G-Code is natively in mm/min)


The link below is extremely useful, a glossary of G-Code commands for RepRap style printers
http://reprap.org/wiki/G-code

Scripts Tab:

Screen Shot 2015-01-19 at 1.14.53 AM.png
Starting G-Code:

This is the G-Code that will be ran after heating up but before your print. Traditionally, this will consist of homing the printer, potentially purging the nozzle, wiping the nozzle and running an auto-leveling function if the printer supports it. In addition, you can add PID values, or set toolhead offsets here if you'd like to.

If you're not a fan of the fact that Simplify3D heats up the bed/extruder, than runs your starting-script, you can customize this, by using the commands below. If you have the commands for [bed#_temperature] or [extruder#_temperature] in your starting G-Code script, the software won't add in heating commands, it will just run off of the commands in your starting script.

[fan_speed_percentage]
[fan_speed_pwm] - for example, M106 S[fan_speed_pwm]
[extruder0_temperature] - for example, M104 S[extruder0_temperature] T0; this will take the layer 1 temperature for extruder 0
[extruder1_temperature]
...
[bed0_temperature] - for example, M140 S[bed0_temperature] T0; this will take the layer 1 temperature for bed 0
[bed1_temperature]
...

Layer Change G-Code:
I personally haven't had to use this, but I'm sure that there are some excellent reasons/ideas to use for this. If you'd like for a G-Code script to be inserted in-between each layer, than you can simply place it in this tab. One interesting use of this, is for the FlashForge Dreamer, to have the lights blink in between each layer, however that can be a bit too much at times! The placeholders that are available for this tab are below:

[previous_Z_position]
[current_Z_position]

Tool Change G-Code:

This tab will insert G-Code on tool change commands. These commands can help do a ton of things for multiple extruder prints, especially if using the IF command functionality. For instance, if you wanted to change the temperature of your extruders (T0, and T1) for each tool change switch:

G28 X0 Y0; homes X-Y axis
{IF NEWTOOL=0}M104 S165 T1; set T1, inactive extruder to 165 C
{IF NEWTOOL=0}M109 S220 T0; Set T0, new active extruder to 220 and wait for it to reach temperature before proceeding.
{IF NEWTOOL=1}M109 S220 T1; set T1, Heat T1 to 220
{IF NEWTOOL=1}M104 S165 T0; Cool T0 to 165

If you were using one process (printed part with one extruder, support with the other), you would only need this script in your one process. However, if using multiple processes, you would need to copy+paste this into each process.

{IF OLDTOOL=0}G1 E-10 F1800 - this will only include the line that follows the {IF} brackets if the old tool (the one that was active prior to the tool change) is tool 0. You could use scripts like this to have different tool change retract distances for different tools
{IF NEWTOOL=0}G1 E10 F1800 - similar to the above command, however it checks the new tool (the one that will be active after the tool change)
[old_tool]
[new_tool]
[current_position_z]


Ending G-Code:

Usually the Ending G-Code's purpose will be to get the nozzle off of the part and then turn off the heaters/motors. The Ending G-Code below is taken from the RoBo 3D profile:

M104 S0 ; turn off extruder
M140 S0 ; turn off bed
G28 X0 ; home X axis
M84 ; disable motors

The placeholders available for the Ending G-Code:
[current_Z_position]

Post Processing:

Create X3G file for MakerBot printers using GPX plugin: This is enabled for all of the MakerBot(Not 5th Gen MakerBot)/Sailfish style printers. The conversion will take your Machine Profile from the X3G tab of the Firmware Configuration and use that to convert your G-Code file to X3G. When you click Save Toolpaths to disk after slicing, the X3G file is automatically created when you save a .Gcode file.

Add Celebration to end of build: Add song to end of build, using Random always keeps things new when printing :lol:

Create .MakerBot file for 5th generation printers: Converts the G-Code file into .MakerBot file. Similar to the X3G, when you click Save Toolpaths to disk after slicing, the .MakerBot file is automatically created when you save a .Gcode file.

Additional Terminal Commands for Post Processing:

If you are using a custom GPX ini file, this a very important section, as you will need to reference GPX in this section rather than use the built-in functionality. There's also a ton of post-processing commands below that help for those who are working with custom firmwares, or doing projects with their printers that require more functionality.

Using the Post Processing box would be if using a MakerBot/Sailfish style printer that doesn't have traditional steps-per-mm values, you would need to do the following:

1) Use the Machine ini example to set a text document ini with your machine information: https://github.com/whpthomas/GPX/blob/m ... achine.ini
2)Save the file as GPX.ini, place it in the Simplify3D installation folder
3)Place the following in the post-processing box: GPX [output_filepath]

Below are the post-processing tools that also work in the post-processing box:

{REPLACE "E" "A"} - search and replace for the text within quotes, in this example every "E" character would be replaced with an "A" character
{PREPEND "G92 E0\n"} - prepends the specified text at the very beginning of the gcode file, note that the \n is converted into a true newline character, not two separate "\" and "n" characters
{APPEND "G28 X0 Y0\n"} - appends the specified text to the very end of the gcode file
{DELETE "M82\n"} - deletes every occurrence of the specified text from the gcode file, note that it will not automatically delete a line if it is suddenly empty after the deletion, so that is why you might want to include the \n at the end (so that the empty line is also removed)
{STRIP ";"} - completely deletes every line in the gcode file that begins with the specified text
{TOOL0REPLACE "E" "A"} and {TOOL1REPLACE "E" "B"} - these special TOOL#REPLACE commands will do a search and replace, very similar to the {REPLACE} command, however, the replace only occurs if the specified tool is active. For example, when using TOOL1REPLACE, the replacement will only occur if tool 1 was currently active at that line of the gcode file
Last edited by S3D-Jake on Mon Jul 23, 2018 11:37 am, edited 1 time in total.
Reason: current_Z_position updated to current_position_z
ghiom
Posts: 21
Joined: Sat Sep 20, 2014 12:06 pm

Re: Tip of the Day 8- Scripts tab, G-Code

Hello, my goal is to mix color.
My idea is to change the tool at every layer.
By this way, when your are not to close of the printerd object , it's seems colors mixed from the 2 colors.

Layer change g-code tab is onbly able to add a line between previous and current Z position.
so i managed to do my effect like this :

In the layer change g-code tab i put this code
[previous_Z_position]
T1
[current_Z_position]
then, in a text editor ( windows notpad ) i'm searching all the T1 ( at layer change ) and replace T1 by T0 one time in 2.
It's a big job to do it by hand in notpad when you have a lot of layers .

did you know a text editor wich beeing able to automate a replace one time in two ?
Because it's works ! One layer on two are differents colors !

thanks for your help
blaknite7
Posts: 30
Joined: Fri Aug 22, 2014 6:57 pm

Re: Tip of the Day 8- Scripts tab, G-Code

This is an awesome post! I did have a couple questions though:

I've been working a lot with dual head prints and I am trying the tweak in the settings... With regard to the tool change g-code and reducing temperatures of the inactive extruder, is it not possible to reference the extruder temperature variable and use it in the tool change g-code?

For example I mean this:
From:
G1 X0 Y40 F4000 ; move to wait for temperatures
{IF NEWTOOL=0}M104 S165 T1; set T1, inactive extruder to 165 C
{IF NEWTOOL=0}M109 S205 T0; Set T0, new active extruder to T0 Temperature and wait for it to reach temperature before proceeding.
{IF NEWTOOL=1}M104 S165 T0; Cool T0 to 165
{IF NEWTOOL=1}M109 S205 T1; set T1, Heat T1 to T1 Temperature


To:

G1 X0 Y40 F4000 ; move to wait for temperatures
{IF NEWTOOL=0}M104 S165 T1; set T1, inactive extruder to 165 C
{IF NEWTOOL=0}M109 S[extruder0_temperature] T0; Set T0, new active extruder to T0 Temperature and wait for it to reach temperature before proceeding.
{IF NEWTOOL=1}M104 S165 T0; Cool T0 to 165
{IF NEWTOOL=1}M109 S[extruder1_temperature] T1; set T1, Heat T1 to T1 Temperature

The reason for doing this is to have different temperatures at different layers that are controlled by the temperature tab in the settings... It didnt seem to work for me when i tried it so i was curious if there is another way to reference the temperature/layer tables defined?

Also, there seems to be a slight pause when switching tools prior to the move "G1" code in the tool change script. is there a way to minimize this/eliminate this? Normally its not so bad but if you have a small feature you are trying to print the dwell tends to screw up the finish.

thanks for the input. Hopefully someone figured this out already.


Advice for those that want to use this functionality, you may want to change the order from the original post of what tools are activated and when. if you command it to wait for temperature (M109) first and then set the inactive extruder to a lower temperature it will operate in that order. Its more often best to always command the inactive extruder to the lower temp first and then the active extruder to the target temp/stabilize. This prevents extra ooze from the soon to be inactive extruder while the new tool head is warming up.
Kyuubi
Posts: 4
Joined: Sun May 17, 2015 8:07 am

Re: Tip of the Day 8- Scripts tab, G-Code

I want post too the LCD "(current layer) of (layers)" on every layer change, is that possible?
User avatar
KeyboardWarrior
Posts: 480
Joined: Thu Jun 19, 2014 5:02 pm

Re: Tip of the Day 8- Scripts tab, G-Code

Kyuubi wrote:I want post too the LCD "(current layer) of (layers)" on every layer change, is that possible?
Since there isn't a current layer or # of layers variable, this isn't currently doable. If you're looking to do this for time-measurement reasons, I don't think that # of layers is a great indicator of speed by the way, since some layers will take much longer than others.

For instance, a pyramids base layers will print much slower than the layers towards the tip.
mmcginnis9272
Posts: 18
Joined: Fri Jun 26, 2015 5:44 pm

Re: Tip of the Day 8- Scripts tab, G-Code

<deleted>

New topic created.
Last edited by mmcginnis9272 on Thu Jul 09, 2015 6:33 am, edited 1 time in total.
JoeJ
Posts: 1435
Joined: Sun Feb 16, 2014 10:52 am

Re: Tip of the Day 8- Scripts tab, G-Code

This really should be a new topic.
ShaqFoo
Posts: 1
Joined: Thu Jul 23, 2015 1:48 am

Re: Tip of the Day 8- Scripts tab, G-Code

KeyboardWarrior wrote:
Kyuubi wrote:I want post too the LCD "(current layer) of (layers)" on every layer change, is that possible?
Since there isn't a current layer or # of layers variable, this isn't currently doable. If you're looking to do this for time-measurement reasons, I don't think that # of layers is a great indicator of speed by the way, since some layers will take much longer than others.

For instance, a pyramids base layers will print much slower than the layers towards the tip.
Great post but he never asked about time measurement. The single biggest reason to display the layer height on the LCD screen is in the case of failed print so you know where to resume by LAYER #. Yes, you could do it by z height too, but visually seeing the layer number is easier to remember and find in the gCode file that S3D creates. S3D inserts the layer# and z height in the gcode for every layer printed but it puts inserts them as comments.

After reading the post, I was really intrigued by the terminal post processing window and was able to display both the layer # and the Z height on the LCD screen during the print for every layer printed. See attached pictures.

Place the following code in the post processing window and you will get layer number printed on your LCD screen along with the z height. The replace command simply removes the comment and replaces it with the M117 command. The second line is for formatting only it is not needed but tightens things up.

{REPLACE "; layer" "M117 Layer"}
{REPLACE " Z = " " Z="}
Attachments
lcd-screens.jpg
nka
Posts: 7
Joined: Wed Aug 05, 2015 8:11 am

Re: Tip of the Day 8- Scripts tab, G-Code

Can I do calculation, like something like this to raise the nozzle 10mm at the end of a print?

G0 X0 Y0 Z{[current_Z_layer]+10}

?
CompoundCarl
Posts: 2005
Joined: Wed Aug 05, 2015 7:23 am

Re: Tip of the Day 8- Scripts tab, G-Code

nka wrote:Can I do calculation, like something like this to raise the nozzle 10mm at the end of a print?

Just use relative mode. See below.

Code: Select all

G90 ; change to relative mode
G1 Z10 F3000 ; raise nozzle 10mm in Z-axis
G91 ; switch back to absolute mode
It's the same thing that S3D uses with their jog controls

Return to “General Discussion and Tips”