Notifications
Clear all

Gcode conditional syntax  

  RSS
Gauthier
(@gauthier)
Eminent Member
Gcode conditional syntax

Here is a gcode bit I got from the forum:

M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{...

I don't understand the =~/ part. The documentation I could find about gcode comparisons mentions that anything in exprtk should work, and that includes singe equal as equality comparison. The tilde ~ in that context and position doesn't make sense to me. Is it a NOT? Is it some kind of indication that the following is a regex? Where is this documented?

Publié : 14/03/2021 3:37 pm
bobstro
(@bobstro)
Illustrious Member
RE: Gcode conditional syntax

That's PERL syntax as used in the original Slic3r, but it's similar to many other programming languages. =~ means "contains" and is used to match if a pattern is present in a string. The slashes (/) delimit the regular expression being matched. The PrusaSlicer regular expressions get pretty funky as they grow longer and longer. Unless you're sharing this profile with others, it is easiest to just plug in the values that you want to use with your printer and avoid the regular expressions.

My notes and disclaimers on 3D printing

and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan

Publié : 14/03/2021 9:15 pm
Dan Rogers
(@dan-rogers)
Noble Member
RE: Gcode conditional syntax

M900 K ... my favorite command.  Linear advance level.  For water proof prints - those that I don't want to fill with water when I send them down 190 feet of salt water - I know this syntax, but I didn't ever guess that it meant "contains". Thank you.  Even easier to parse.

For those who worry about linear advance, there is an override in the main settings - you can disable linear advance there.  I think.  At least I told it to.  Saves me having to fuss with M900 K0;

 

Publié : 15/03/2021 12:13 am
bobstro
(@bobstro)
Illustrious Member
RE: Gcode conditional syntax
Posted by: @dan-rogers

[...] For those who worry about linear advance, there is an override in the main settings - you can disable linear advance there.  I think.  At least I told it to.  Saves me having to fuss with M900 K0;

I'm not aware of a PrusaSlicer setting that will disable linear advance settings inserted in custom filament gcode. These lines are just inserted raw at the start of a print. Open up a gcode file in a text editor and verify that the M900 Kxx line is not present.

My notes and disclaimers on 3D printing

and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan

Publié : 15/03/2021 5:14 am
Gauthier
(@gauthier)
Eminent Member
Topic starter answered:
RE: Gcode conditional syntax

@bobstro

Thanks! I'm a programmer, yet I've managed to almost never use Perl. I'm surprised that the fact the Slic3r (may) use Perl here did not pop up in my searches! Here to hoping that the next person searching for it will find this thread.

Publié : 15/03/2021 7:23 am
Partager :