Jump to content
Ultimaker Community of 3D Printing Experts

Postprocessing PlugIn Script, how to display a pop up message


Cuq
 Share

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 · Postprocessing PlugIn Script, how to display a pop up message

    Why raise a SyntaxError though? That's like using a hammer to stir your coffee. Wouldn't a simple "return" work?

    • Like 1
    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
     Share

    • Our picks

      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...