Jump to content

Postprocessing PlugIn Script, how to display a pop up message


Cuq

Recommended Posts

Posted · Postprocessing PlugIn Script, how to display a pop up message

Hello,

 

Is it possible to display a message in a Python Cura Postprocessing PlugIn Script. I know how to add a log text via :

from UM.Logger import Logger

Logger.log('d',  "Error" )

I have tried 

 

from UM.Logger import Logger
from UM.Message import Message
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")

 Message("Error\n", title = catalog.i18nc("@info:title", "Post Processing")).show()

 But it doesn't work

  • Link to post
    Share on other sites

    Posted (edited) · Postprocessing PlugIn Script, how to display a pop up message

    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')

     

    Message.jpg

    Edited by Cuq
  • Link to post
    Share on other sites

    Posted (edited) · Postprocessing PlugIn Script, how to display a pop up message
    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
  • Link to post
    Share on other sites

    Posted · Postprocessing PlugIn Script, how to display a pop up message

    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.

    • Like 1
    Link to post
    Share on other sites

    Posted (edited) · Postprocessing PlugIn Script, how to display a pop up message
    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
  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • Introducing Universal Cura Projects in the UltiMaker Cura 5.7 beta
        Strap in for the first Cura release of 2024! This 5.7 beta release brings new material profiles as well as cloud printing for Method series printers, and introduces a powerful new way of sharing print settings using printer-agnostic project files! Also, if you want to download the cute dinosaur card holder featured below, it was specially designed for this release and can be found on Thingiverse! 
          • Like
        • 10 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...