conditional g-code, alternative to curly braces?
-
Is there an alternative pair of characters that can be used in conditional g-code instead of curly braces?
My reason for asking is that having curly braces in Cura's machine start g-code can break cura's setting replacement. As a real example, the following in my cura startup-gcode works as expected:
G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2
...results in the following being written to the gcode file:
G10 L2 P2 X0.6 Y50 Z20However, if I put the following two lines in the cura start g-code, it appears that cura gets confused by unrecognized tokens in curly braces, and therefore refuses to do ANY substitution at all:
G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2 M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60}
... resulting in the above two lines being copied to the gcode exactly as typed above without replacing "retraction_amount", etc (making it useless.)
At the moment, I'm working around this issue by putting the M207 call into a macro file, and then calling the macro from the start gcode.
-
@garyd9 that's a tricky one. No doubt you have seen that sub expressions in conditional gcode can use () brackets instead (but that does not help here).
I tried a few ideas in Cura to escape those characters but that did not help, you can see in the cura log files it gives up;
2021-03-01 23:48:08,310 - WARNING - [Thread-8] UM.Logger.logException [106]: Exception: Unable to do token replacement on start/end g-code 2021-03-01 23:48:08,313 - WARNING - [Thread-8] UM.Logger.logException [110]: Traceback (most recent call last): 2021-03-01 23:48:08,315 - WARNING - [Thread-8] UM.Logger.logException [110]: File "C:\Program Files\Ultimaker Cura 4.8.0\plugins\CuraEngineBackend\StartSliceJob.py", line 395, in _expandGcodeTokens 2021-03-01 23:48:08,318 - WARNING - [Thread-8] UM.Logger.logException [110]: return str(fmt.format(value, **settings)) 2021-03-01 23:48:08,320 - WARNING - [Thread-8] UM.Logger.logException [110]: File "string.py", line 191, in format 2021-03-01 23:48:08,322 - WARNING - [Thread-8] UM.Logger.logException [110]: File "string.py", line 195, in vformat 2021-03-01 23:48:08,324 - WARNING - [Thread-8] UM.Logger.logException [110]: File "string.py", line 235, in _vformat 2021-03-01 23:48:08,326 - WARNING - [Thread-8] UM.Logger.logException [110]: File "string.py", line 306, in get_field
One option that might be worth exploring is using the post processing script to run a search replace on a comment line or similar to generate that line for you. but the macro solution is easier!
-
This is one of the reasons I abandoned Cura in favour of PrusaSlicer.
You could maybe put all your RRF stuff in a special character that replaces the curly braces (like #move.axes[0].min~) and then run two search and replace post processing scripts to replace it with curly brackets again.M207 S#move.axes[0].workplaceOffsets[1]~ R0 F#move.axes[1].workplaceOffsets[1] * 60~ T#move.axes[2].workplaceOffsets[1] * 60~
Output becomes
M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60}
-
@OwenD
Actually # is a bad example to use as it's used in RRF meta commands but you get the idea -
Just a thought: have you tried:
M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
or:
M207 S{(move.axes[0].workplaceOffsets[1])} R0 F{(move.axes[1].workplaceOffsets[1] * 60)} T{(move.axes[2].workplaceOffsets[1] * 60)}
-
@dc42 said in conditional g-code, alternative to curly braces?:
Just a thought: have you tried:
M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
Nailed it!
G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2 M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
Gives this output in Cura 4.6.1
G10 L2 P2 X3 Y20.0 Z20.0 ; put retraction settings in workspace2 M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60}
The second example fails to process both lines.
-
@dc42 said in conditional g-code, alternative to curly braces?:
M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
I can confirm that doubling the curly braces does appear to work. Thank you.
Gary