Page 1 of 2

Output literal double quotes with the REPLACE command?

Posted: Wed Jan 10, 2018 10:00 am
by smeagollum
To insert pauses (or anything you want) for changing filament S3D supports using the REPLACE command in the post processing scripts tab, which is good.

However, I'd like to be able to output literal double quote characters (") in the replace text (to have the printer display a text). Some printers accept text added to the pause command, example:

M25 "Change to RED"

However, the double quotes surrounding the text interferes with the replace command, so this doesn't work. Escaping the double quotes (with a \) doesn't work either.

Is this possible, or is an external text tool needed to achieve this (not difficult to do, but built-in is preferred when possible)?

Re: Output literal double quotes with the REPLACE command?

Posted: Wed Jan 10, 2018 3:52 pm
by horst.w
I have tried some possibilities but it seems, there is a obstacle you can not solve.

First:
To insert the M-Code M25 on a certain place is easy to do when you have a clear defined goal such as " layer 1 ".
But you insert a command and commands must be conform to the conventions.
M25 " .... " is not conform and
M25; "change to Red" is after the semicolon a text, but this text will not be readed to execute.

Second:
The M25 command interupts the print and I have no informations found, that it also can write a text to the display
There is surely existing another command to display textes but I dont know any one.

Third:
M25 stops all following commands just to the resume signal.
Inserting an additional command below the M25 will not be execute when pausing. Inserting an additional command above M25 must hold the text on the display as long as M25 stops all other commands :?

>>> http://reprap.org/wiki/G-code

Regards
horst.w
GER

Re: Output literal double quotes with the REPLACE command?

Posted: Wed Jan 10, 2018 5:46 pm
by smeagollum
Ok, thanks. The M25 command itself is not the question, some printers also use other commands to pause, the point was that in my case the double quotes around the text to display are necessary, and it is currently not possible to output those with this command in Simplify3D.

Using an external tool is therefore the only option for this specific case.

Re: Output literal double quotes with the REPLACE command?

Posted: Wed Jan 10, 2018 6:57 pm
by horst.w
smeagollum wrote:
...
Using an external tool is therefore the only option for this specific case.
... that needs only e.g. MS-Note++ >>> search & replace. GCode is only a text file.

H.

Re: Output literal double quotes with the REPLACE command?

Posted: Wed Jan 10, 2018 7:39 pm
by dkightley
I wonder if there's a way of invoking some form of metacharacter that represents the literal double quote character that can be differentiated by the interpreter for the code that S3D is written in.

\n is interpreted as a CRLF....so I wonder if there's an equivalent for double quote......perhaps \" or "" or even chr(34)


The last two are used in classic ASP and (I think) JavaScript. I've not used post processing in S3D....so it's likely to be fruitless for me to try testing these permutation.

Just a thought.....

Re: Output literal double quotes with the REPLACE command?

Posted: Thu Jan 11, 2018 1:25 am
by arhi
use M117 to send message, no need for quotes

so something like

Code: Select all

{REPLACE "; layer 7," "M117 Change to RED\nM25\n; layer 7,"}
This way you will send M117 Change to RED which will display Change to RED on your printer screen and after that a blank M25.. that should keep the old message on the screen and pause the print... (M25 without txt afterwards should not clear previous message from the screen)

Re: Output literal double quotes with the REPLACE command?

Posted: Mon Mar 02, 2020 3:24 am
by flaviocu
Hi
Sorry to dig up this old post again. But I have the same Problem and I did not find a workaround. I'd like to replace a command and in the replacement string I need to enclose a string in double quotes. Anyone's got an Idea on how that could work?

I've tried:
- Escaping \"
- Enclosing """

And both didn't work. Unfortunately using single quotes doesn't work on the Command side...

Thank you for your help

Re: Output literal double quotes with the REPLACE command?

Posted: Fri Apr 16, 2021 6:04 pm
by DonStauffer
Surely this is possible, somehow. Post-processing is often used to add Gcode commands, and some of those require double quoted parameters.

Has anyone yet figured out how to include literal double quotes in the REPLACE post-processing construct?

Re: Output literal double quotes with the REPLACE command?

Posted: Sat Apr 17, 2021 8:58 am
by DonStauffer
The best I've been able to do is use a unique series of characters, install GnuWin sed, and create a batch file to do the substitution.

{REPLACE "; Settings Summary" "; Settings Summary DoubleQuotesxDoubleQuotes"}
"C:\Users\Don\3D Printing\Temp\DoubleQuotes.BAT" "[output_filepath]" "[output_dir]\[output_filename]_2.gcode" "[output_filename].gcode"

DoubleQuotes.Bat:

:: %1 Output filespec
:: %2 Temp filespec
:: %3 Output filename

"C:\Program Files (X86)\GnuWin32\bin\sed.exe" "s/DoubleQuotes/\d34/g" %1 > %2
del %1
ren %2 %3

Believe it or not, this took an entire day to develop because of idiosyncrasies of post-processing scripts, especially pertaining to double quote handling!

Re: Output literal double quotes with the REPLACE command?

Posted: Sat Apr 17, 2021 2:43 pm
by DonStauffer
If you put the following code in a file named ReplaceWithQuotes.BAT, and install the GnuWin sed utility, you should be able to use it as noted in the header comments to work around the {REPLACE...} issue with literal quote characters:

@ECHO OFF
GOTO Start

********************************************************************************
ReplaceWithQuotes.BAT <Directory> <BaseFilename> <Extension> <Placeholder> [-v]
********************************************************************************
Batch Arguments (in Simplify3D post-processing)
********************************************************************************
The <Directory> argument should be "[output_dir]".
The <BaseFilename> argument should be "[output_filename]"
The <Extension> argument does not include the dot.
The <Placeholder> argument should be the string to be replaced by double quotes.
The optional -v argument produces more log file information for troubleshooting.
********************************************************************************
Example Usage (in Simplify3D post-processing)
********************************************************************************
{REPLACE "; feature solid layer" "; feature solid layer\nM98 PDoubleQuotesSolidSettingsMacroDoubleQuotes"}
"<Directory>\ReplaceWithQuotes.BAT" "[output_dir]" "[output_filename]" gcode DoubleQuotes -v > <Directory>\QuoteLog.txt
********************************************************************************
This would result in all the lines which contained
; feature solid layer
to now be followed by the line:
M98 P"SolidSettingsMacro"
********************************************************************************
Description
********************************************************************************
Simplify3D 4.1.2 has a useful post-processing script facility (Scripts tab,
"Additional terminal commands for post processing"). The post-processing script
includes a {REPLACE...} feature, but nobody knows how to make it insert code
which includes double quotes. Possibly it can't. But some gcode commands take
parameters which require double quotes.

This batch file is part of a workaround. It's intended to be called from the
post-processing script, with arguments which enable it to find a gcode file
which contains a "placeholder" - a particular unique series of characters -
representing double quotes. The batch file uses the GnuWin sed utility to
substitute actual double quote characters for each instance of that placeholder
in the gcode file.
********************************************************************************
Issues
********************************************************************************
Simplify3D 4.1.2 post processing scripts have some problems with paths.

Provide the full path to this batch file, and quote it if it includes spaces.
Otherwise, it may silently fail. It's unclear where Simplify3D will look for it.

If you include a log file (redirection target), provide the full path, but be
sure it doesn't include any spaces and is unquoted. If you don't include a
complete path to the log file, the batch will silently fail to make the
replacements, and won't cretae a log either! If you include a complete path,
but either (or both) the path contains at least one space, or the filespec is in
quotes (ironically), the batch will make the replacements, but won't produce a
log file. If you don't include a log file (redirection), the batch will make the
replacements.
********************************************************************************
Don Stauffer, April 2021
********************************************************************************

: Start

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: Put parameters into variables with more descriptive names

SET Directory=%~1
SET BaseFilename=%~2
SET Extension=%~3
SET Placeholder=%~4
IF /i "%5" EQU "-v" SET IsVerbose=1

IF DEFINED IsVerbose (
@ECHO ReplaceWithDoubleQuotes.BAT

For /F "Tokens=*" %%I in ('Date /T') Do Set DateTime=%%I
For /F "Tokens=*" %%I in ('Time /T') Do Set DateTime=!DateTime!at %%I
@ECHO !DateTime!
)

:: Construct output and temporary filenames and filespecs

SET Filename="%BaseFilename%.%Extension%"
SET Filespec="%Directory%\%BaseFilename%.%Extension%"

SET TempFilename="%BaseFilename%_Temp.%Extension%"
SET TempFilespec="%Directory%\%BaseFilename%_Temp.%Extension%"

IF DEFINED IsVerbose (
@ECHO.
@ECHO Filename=%Filename%
@ECHO Filespec=%Filespec%
@ECHO TempFilename=%TempFilename%
@ECHO TempFilespec=%TempFilespec%
)

:: Construct and execute sed command

SET SedFilespec="C:\Program Files (X86)\GnuWin32\bin\sed.exe"
SET SedScript="s/%Placeholder%/\d34/g"
SET SedCommand=%SedFilespec% %SedScript% %Filespec%

IF DEFINED IsVerbose (
@ECHO.
@ECHO %SedCommand% ^> %TempFilespec%
)

%SedCommand% > %TempFilespec%

:: Replace output file with temporary file

IF DEFINED IsVerbose (
@ECHO.
@ECHO DEL %Filespec%
)

DEL %Filespec%

IF DEFINED IsVerbose (
@ECHO.
@ECHO REN %TempFilespec% %Filename%
)

REN %TempFilespec% %Filename%