Why raise a SyntaxError though? That's like using a hammer to stir your coffee. Wouldn't a simple "return" work?
-
1
Why raise a SyntaxError though? That's like using a hammer to stir your coffee. Wouldn't a simple "return" work?
34 minutes ago, ahoeben said:Why raise a SyntaxError though? That's like using a hammer to stir your coffee. Wouldn't a simple "return" work?
That's a good question and you can certainly help me on this point. I can use just "return" like :
return('; Gcode must be generate in relative extrusion')
In this case this return will generate an error 'TypeError: 'str' object does not support item assignment' but the advantage No Gcode Will be generated and I will get just the Error Message . But it's not a 'Clean Solution'
Or I can also return the data with just one line. But how to resize the data item ?
data.resize(0)
data[0] = '; Gcode must be generate in relative extrusion'
return data
Edited by Cuq
If you must raise something, riase an Exception instead of a SyntaxError. Because the error is not related to the syntax at all.
I would advice against removing all gcode, because the user will not see that and an empty file will be saved but Layer View will still show the original sliced layers.
35 minutes ago, ahoeben said:I would advice against removing all gcode, because the user will not see that and an empty file will be saved but Layer View will still show the original sliced layers.
Ok Finaly As I prefer to not generate anything I will use :
if relativeextrusion == False:
#
Logger.log('d', 'Gcode must be generate in relative extrusion mode')
Message('Gcode must be generate in relative extrusion mode', title = catalog.i18nc("@info:title", "Post Processing")).show()
return None
In case of wrong setting, I will get just the error message , No file generated, No message in relation of a generated file, No risk to print something which is not correct or can generate inappropriated extruder instructions.
Thanks again for your help @ahoeben
Edited by Cuq
Recommended Posts
ahoeben 1,852
What do the logs say?
Link to post
Share on other sites
Cuq 173
Thanks @ahoeben , finaly it was just a problem of speed, the message was displayed but as extra messages were displayed, I wasn't seen the message in the Cura software. I 'solved' this issue by adding a Raise instruction to stop the script:
from ..Script import Script from UM.Logger import Logger from UM.Application import Application from cura.Settings.ExtruderManager import ExtruderManager from UM.Message import Message from UM.i18n import i18nCatalog import re #To perform the search and replace. catalog = i18nCatalog("cura") ... extrud = list(Application.getInstance().getGlobalContainerStack().extruders.values()) infillpattern = extrud[extruder_id].getProperty("infill_pattern", "value") relativeextrusion = extrud[extruder_id].getProperty("relative_extrusion", "value") if relativeextrusion == False: # Logger.log('d', 'Logger: Gcode must be generate in relative extrusion') Message('Message : Gcode must be generate in relative extrusion', title = catalog.i18nc("@info:title", "Post Processing")).show() raise SyntaxError('SyntaxError : Gcode must be generate in relative extrusion')
Link to post
Share on other sites