Jump to content

Plugin help: How to detect when print setting change?


bradk3
Go to solution Solved by ahoeben,

Recommended Posts

Posted · Plugin help: How to detect when print setting change?

Hi, everybody! 

 

I'm working on a Cura plugin that needs to be able to detect when a change has been made to the print settings (in particular, Layer Height).  I've looked around and can't seem to find the event to attach to.  Does anyone know off-hand how I could do this?

  • Link to post
    Share on other sites

    • Solution
    Posted (edited) · Plugin help: How to detect when print setting change?

    I think you are looking for the "propertyChanged" signal of the "global stack".  To connect to it, you first need to connect to the "globalContainerChanged" signal of the machine manager. So something like this (untested code, there may be typos):

        def __init__(self, parent: Optional[QObject] = None) -> None:
            (...)
            self._global_stack = None  # type: Optional[GlobalStack]
            machine_manager = cura.CuraApplication.CuraApplication.getInstance().getMachineManager()
    
            # Reconnect all signals when the active machine gets changed.
            machine_manager.globalContainerChanged.connect(self._onMachineChanged)
            (...)
    
        def _onMachineChanged(self) -> None:
            if self._global_stack:
                self._global_stack.propertyChanged.disconnect(self._onPropertyValueChanged)
    
            self._global_stack = self._machine_manager.activeMachine
    
            if self._global_stack:
                self._global_stack.propertyChanged.connect(self._onPropertyValueChanged)
    
        def _onPropertyValueChanged(self, key: str, property_name: str) -> None:
            if key == "layer_height":
                Logger.log("d", "Layer Height changed")

     

    Edited by ahoeben
    • Thanks 2
    Link to post
    Share on other sites

    Posted · Plugin help: How to detect when print setting change?

    Thank you!  I sort of found the right callback, but had to do some work-arounds because I didn't know about the need to connect to the globalContainerChanged callback.

     

    Thank you for taking the time to explain that.  This is exactly what I needed.

    • Like 2
    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 the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Like
        • 3 replies
      • UltiMaker Cura 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 26 replies
    ×
    ×
    • Create New...