Broncosis
Posts: 4
Joined: Tue Sep 01, 2015 1:56 am

post processing script

Tue Sep 08, 2015 12:04 am

I have noticed that when using the replace command to add multiple lines of gcode
makes for issues with the commented section at the top of the file
it tries to run the commands you add

this is my script for changing color it works fine even though before my printer heats up it tries to run the code not a huge deal I have to press the button one
extra time
{REPLACE "; layer 3" ";move away and pause \nG1 Z10 F1800 \nG1 Y10 X10 F3000 \nM0 \nG92 E0 \nG1 E-1.7500 F900 \n; layer 3"}
this is what I put in the profile

here is the code i puts in the top section of the file where s3d stores all the parameters lines 150-166 of my gcode file

; postProcessing,{REPLACE ";move away and pause
G1 Z10 F1800
G1 Y10 X10 F3000
M0
G92 E0
G1 E-1.7500 F900
; layer 3" ";move away and pause \nG1 Z10 F1800 \nG1 Y10 X10 F3000 \nM0 \nG92 E0 \nG1 E-1.7500 F900 \n;move away and pause
G1 Z10 F1800
G1 Y10 X10 F3000
M0
G92 E0
G1 E-1.7500 F900
; layer 3"}
; defaultSpeed,6000
; outlineUnderspeed,0.65
; solidInfillUnderspeed,0.8
; supportUnderspeed,0.8
Attachments
bizcardpause.gcode
the whole gode file
(357.15 KiB) Downloaded 301 times

SimpleScott
Posts: 42
Joined: Tue Jan 12, 2016 7:23 pm

Re: post processing script

Sun Jan 17, 2016 7:17 pm

+1. I've run into this problem as well when trying to setup a Pause for filament change in S3D.

S3D adds the entire text of any REPLACE command (including the "Search for" text) into a comment near the top of the gcode, prefixed with "postProcessing". Good for documentation, but then when it subsequently executes the REPLACE command, the "Search for" text can match itself and that ends up adding the replacement Gcode sequence into the comment area, as well as at the intended target lines.

As a fix, I would suggest S3D not apply REPLACE commands to comment lines.

In the meantime, I found a workaround. When executed, the REPLACE command is searching for the actual character sequence, not the escaped text representation of the sequence. So if you include "\n" in the "search for", then the search will only match a real newline character (i.e., single byte #10) and not the two-character text sequence of "\n". That way it can't match itself in the postProcessing comment line.

So I changed my REPLACE command to look like this:
{REPLACE "\n; layer 5," "\n;***PAUSE***\nM83\nG1 E-1.000000 F6000\nG91\nG1 Z5.000\nG90\nG1 X10 Y10 F6000\nM84 E0\nM0\nM82\nG92 E0\n;layer 5,"}

When executed, that is looking for "<newline>; layer 5" (where <newline> is a single #10 byte), which matches the intended target line BUT it does not match the "\n; layer 5" (where newline is represented by the two-character escape sequence \n). That means it doesn't match the S3D-inserted "postProcessing" comment line, and extra Gcode is not inserted at that point.

Of course what I would REALLY LIKE TO SEE... I'd like a spot on the "Layer" tab where I can specify a PAUSE for any particular layer(s), along with someplace where I can define that PAUSE executes a specific sequence of Gcode. That way I can define the block of Gcode and have it arbitrarily inserted where I want -- without the problems of text matching and character substitution which accompany the REPLACE method.

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

Re: post processing script

Mon Jan 18, 2016 7:00 am

Very simple. Just add a {STRIP "; postProcessing"} before your {REPLACE} commands. That will remove that one line from the header.

SimpleScott
Posts: 42
Joined: Tue Jan 12, 2016 7:23 pm

Re: post processing script

Mon Jan 18, 2016 12:52 pm

Thanks, CC. Yes, using using {strip] to remove the comment was the first thing my simple brain thought to try. But doing that removes useful documentation from the file. I like that S3D adds that comment; it is good documentation of how the file was prepared, and I want it there for future reference if I look at the gcode weeks or months from now. It is just too bad it conflicts with the workaround of using post-processing scripts to add Gcode for a pause.

Of course including the beginning of the line (starting with \n) in the "search for" text of the Replace command isn't arduous either. The explanation is long (or at least mine was, lol). But in reality, if someone is up to the task of finding the layer, messing about with a {Replace} command, and writing Gcode to effect a pause and the needed xyze movements, then ensuring that the "Search" text starts with \n doesn't really add to that existing burden.

As for {Replace} changing comment lines... Maybe there is some reason why people would WANT a Replace command to affect comments lines, but I can't think of one. So it seems like {Replace} should ignore the comment lines inserted by S3D.

Of course we wouldn't be discussing that issue if there was a pause function in the GUI. Not everyone wants to write gcode or post-processing scripts. I recall CURA has a "pause at height" function included. Just specify where you want to pause (in mm, not layer, so changing slice parameters doesn't affect it!), and the rest is automatic. No need to write gcode commands, no need to figure out on which layer the desired point is located, no need to mess with post-processing commands. I miss that.

Obviously I dropped CURA and now use Simplify3D. Money well spent. But I still want to see it improved. A simple "pause at height" or even "pause at layer" would be a great improvement, and a lot easier for people who don't want to code post-processing statements or write gcode. :-)

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

Re: post processing script

Tue Jan 19, 2016 7:30 am

FYI - several of the profiles that I use from S3D use the {REPLACE} commands to manipulate the header with info that is needed by those machines. So it definitely needs to work on the header as well ;)

SimpleScott
Posts: 42
Joined: Tue Jan 12, 2016 7:23 pm

Re: post processing script

Tue Jan 19, 2016 10:54 am

CompoundCarl wrote:FYI - several of the profiles that I use from S3D use the {REPLACE} commands to manipulate the header with info that is needed by those machines. So it definitely needs to work on the header as well ;)
My thought was only to exclude the comment lines inserted by S3D from REPLACE.

Would that restrict what you need to change for your machines? I assumed they were all comments, and only for human consumption. I'm genuinely curious to know which machines use those comment lines from the Gcode, as I haven't used that many different printers.

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

Re: post processing script

Tue Jan 19, 2016 1:13 pm

Yes, it would create problems for many of the printers that S3D supports (and that I use!). A lot of the various firmwares out there require special information in the comments that you frequently need to replace when you export the file. So again, I doubt they will disable the {REPLACE} functionality for comments, since that's probably about 50% of what it's used for ;)

SimpleScott
Posts: 42
Joined: Tue Jan 12, 2016 7:23 pm

Re: post processing script

Tue Jan 19, 2016 1:15 pm

Interesting. Can you give an example? I didn't know any of the firmwares acted on comment lines in gcode. I may have capabilities I don't know about!

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

Re: post processing script

Wed Jan 20, 2016 5:50 am

All the XYZ printers, anything that uses BFB codes, and several of my homemade models. It's very common.

SimpleScott
Posts: 42
Joined: Tue Jan 12, 2016 7:23 pm

Re: post processing script

Wed Jan 20, 2016 11:26 am

Do any of those printers use the "postProcessing" comment that S3D inserts? Why would that ever need to be changed by a REPLACE command?

Return to “Troubleshooting and Bug Reports”