Ultimaker / Cura

3D printer / slicing GUI built on top of the Uranium framework
GNU Lesser General Public License v3.0
6.18k stars 2.08k forks source link

Attempting to use calculations in Start/End GCode breaks it without warning about it #9906

Open BloodyRain2k opened 3 years ago

BloodyRain2k commented 3 years ago

Application Version

4.9.1

Platform

Win 7 x64

Printer

CR6

Reproduction steps

Enter characters use in equations into the { } of a placeholder in the Start/End GCode Close the window and let it re-slice the part Save the GCode to disk and verify that it failed to replace the placeholders without any indication

image

Actual results

I want to point out that this is even the 2nd attempt where I commented out the line, and it still broke.

image

Expected results

If it fails to fill in the placeholders because there's something in the GCode that breaks it, I expect it to give me a warning at the very least.

But I can do the whole process and nothing out of the ordinary happens.

On a side note: I was hoping it would be possible to use math with the placeholders, but it was only a test for a tiny QoL thing.

Checklist of files to include

Additional information & file uploads

Bearing_Clip_686.zip

fvrmr commented 3 years ago

Hi @BloodyRain2k thank you for your report. It is expected behaviour you can't uses formulas in the start g-code, so that's why it isn't working.

fvrmr commented 3 years ago

Hi @BloodyRain2k I have discussed it with the team and we decided to defer this issue. It is not a priority right now to add a warning when you want to use formulas in the start/end gcode. Hope you understand.

BloodyRain2k commented 3 years ago

I can understand not wanting to make calculations at this point a priority, but not adding a warning when something broke the parser? That seems bad.

Like when I tried to change my experiment to

M109 S190
M300 P100 S660
M109 S{material_print_layer_0_temperature}

I made a typo in the first line and it read M109 S{190} instead, which also broke every other placeholder, just like the commented line with the placeholder calculation.

At the very least it should warn if something went wrong while filling in the placeholders.

fvrmr commented 3 years ago

I understand, but is not a priority for us to add this, since we have more important bugs to fix. A pull request is always welcome.

Ghostkeeper commented 3 years ago

People add stuff in brackets to their start g-code all the time, especially for firmware like Repetier's. Can't warn them all the time for things that are perfectly valid. So what distinguishes a perfectly valid g-code intended for third party software from an incorrectly formatted setting key intended for Cura to read?

FroggieFrog commented 1 year ago

This issue is still present with 5.3.1. A solution could be to ignore commented lines that fail to parse, but show a warning if the line failed to parse but is not commented.

; do not show warning AND continue to replace other variables
; no arithmetic in cura
;M190 S{material_bed_temperature_layer_0 * 0.7}

; is still parsed and replaced despite the above statemant
M190 S{material_bed_temperature_layer_0}

; show warning | maybe stop slicing
M190 S{material_bed_temperature_layer_0 * 0.7}

relevant information from cura.log:

2023-04-21 09:20:41,870 - INFO - [MainThread] CuraEngineBackend.CuraEngineBackend.slice [290]: Starting to slice...
2023-04-21 09:20:41,870 - DEBUG - [MainThread] CuraEngineBackend.CuraEngineBackend.slice [309]: Going to slice build plate [0]!
2023-04-21 09:20:41,984 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob.get_value [85]: Unable to replace 'material_bed_temperature_layer_0 * 0' placeholder in start/end g-code
2023-04-21 09:20:41,984 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]: Exception: Unable to do token replacement on start/end g-code
2023-04-21 09:20:41,985 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]: Traceback (most recent call last):
2023-04-21 09:20:41,985 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:   File "C:\Program Files\UltiMaker Cura\share\cura\plugins\CuraEngineBackend\StartSliceJob.py", line 417, in _expandGcodeTokens
2023-04-21 09:20:41,986 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:     return str(fmt.format(value, **settings))
2023-04-21 09:20:41,986 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:   File "string.py", line 161, in format
2023-04-21 09:20:41,987 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:   File "string.py", line 165, in vformat
2023-04-21 09:20:41,987 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:   File "string.py", line 205, in _vformat
2023-04-21 09:20:41,988 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]:   File "string.py", line 276, in get_field
2023-04-21 09:20:41,988 - WARNING - [JobQueueWorker [2]] CuraEngineBackend.StartSliceJob._expandGcodeTokens [419]: AttributeError: 'str' object has no attribute '7'
2023-04-21 09:20:42,041 - DEBUG - [MainThread] CuraEngineBackend.CuraEngineBackend._onStartSliceCompleted [516]: Sending slice message took 0.17104196548461914 seconds