Gcode replacement

I may be trying to use gcode replacement for something it wasn't intended for, so any advice would help.

My issue concerns starting gcode. I have several different print profiles that I use in my slicer- prusa. All have custoim gcode for the start of the print. Most of the profiles have the same starting gcode . While some are slightly different. Like most people I tweak my starting gcode from time to time. The issue is that I then have to go back and edit all my profiels with the changes. So, I set out to make a small set of unique start gcodes and just reference them. It didn't appear that I could do this in prusa slicer, so I am trying to do this in repetier.
At first I just thought about using the "Before Job" section. But that had two issues. First, I have about 4 different start gcode sets depending on what I am making. So, I would end up editing that section each time I changed the start. Secondly, when I rerun gcodes that I have run in the past, those files already have the start gcode in them. So I would end up running them twice. 

So I thought the best approach would be to use gcode replacements. I would then make 4 replacement scripts. Each would look for a meaningful text string that I would put in my prusa slicer start gcode. Such as the following:


the replacement code is 47 lines of gcode 

in prusa slicer in the start code section of a specific profile I simply have:


I assumed that I would need to make it look like a comment in my slicer otherwise it would probably choke on it.

However, nothing seems to be happening. I looked at the print log and didn't see the replacements and it didn't seem to make the changes in the actual print. 

Is it because it looks like a comment? The regex worked on the regex site. 


  • Yes, I think it is because of the comment. We remove comments before sending so there is nothing left to replace.

    Try ;@ instead, that is the official server command start that acts also as comment. Havent tested it yet, but think it would work.

    Alternatively you can also use function. Put in server start g-code your codes as function
    @func start1

    and call them instead in your slicer script
    ;@call start1

    that removes the watch for replacements and makes server use less cpu in the end, also a few replacements are no problem at all. Both solutions should work. But with functions you can also use parameter to change behavior or include temperatures as function parameter.
Sign In or Register to comment.