User avatar
BaronWilliams
Posts: 183
Joined: Tue Jul 15, 2014 8:30 pm

Extending Script IF Statements (IF this AND that Logic)

It's possible to create IF statements in chains.

The script interpreter interprets a script line as it reads it from the start. If the first IF is FALSE, then the following text in that line is ignored and doesn't make it into the G-Code output. If the first IF statement is TRUE, it continues to process the following text in that line, including additional IF statements it finds. This allows IF this AND that logic statements.

For example, take a look at this Post Tool Change script:

Code: Select all

{IF "[current_layer_number]==1"}G1 E2 F1800 ; Extrude 2 mm @ 30 mm/s.
{IF "[current_layer_number]==2"}{IF "[current_tool]==1"}G1 E2 F1800 ; Extrude 2 mm @ 30 mm/s.
The first line primes the current tool head if it's at layer 1 only, by extruding 2 mm of filament.

The second line primes the current tool only if it's T1, and only if it's at layer 2.

The factory that uses this special script prints the first layer with T0, and turns on T1 at layer 2 when needed. Since my factory doesn't turn on T1 until layer 2, I can't have it prime at layer 1, and I don't want it oozing while T0 prints layer 1, so it's off for all of layer 1.

The factory will print a prime pillar after each tool change. It's important that the very first layer of the prime pillar for a tool head is printed AFTER the tool head is primed a little first, so that the foundation of the prime pillar is solid and not missing anything. Because T1 in that particular factory print is not used until layer 2, its needs to be primed before printing it's prime pillar at layer 2 where it's prime pillar starts, while T0 needs to do it at layer 1. So this ability to chain IF statements was really handy for this use case.

Return to “General Discussion and Tips”