Jump to content
Ultimaker Community of 3D Printing Experts

Plugin help: How to detect when print setting change?


bradk3
 Share

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

    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
     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...