Jump to content

Plugin help: Detecting when a model is added or deleted from the build platform


bradk3
Go to solution Solved by nallath,

Recommended Posts

Posted · Plugin help: Detecting when a model is added or deleted from the build platform

I would like my plugin to be able to detect when a model is added to or removed to the build platform in Cura. It seems like it should be simple, but I'm clearly not smart enough.

 

The approach I've tried is to connect to the CuraApplication sceneChanged event and watch for changes involving CuraSceneNodes. This works, in that, I can detect when a model is added or removed from the scene, but it also fires when a model is translated or resized, which I do not want.

 

I can't seem to find more information about the scene change, but I may just be clueless. The CuraSceneNode object that is passed to the callback doesn't appear to have any relevant information, nor does the SceneNode object it inherits from.

 

If anyone has any hints, I would appreciate it very much.

  • Link to post
    Share on other sites

    • Solution
    Posted · Plugin help: Detecting when a model is added or deleted from the build platform

    The SceneChanged is a combination of three events:

    def _connectSignalsRoot(self) -> None:
        self._root.transformationChanged.connect(self.sceneChanged)
        self._root.childrenChanged.connect(self.sceneChanged)
        self._root.meshDataChanged.connect(self.sceneChanged)

    What you're looking for is only the "childrenChanged" of the root:

    childrenChanged = Signal()
    """Emitted whenever the list of children of this object or any child object changes.
    
    :param object: The object that triggered the change.
    """
    • Thanks 1
    Link to post
    Share on other sites

    Posted · Plugin help: Detecting when a model is added or deleted from the build platform

    Fantastic! I'm not sure how I missed that in my searching through the source code, but I did.

     

    Thank you for the information. That was exactly what I needed.

    • Like 1
    Link to post
    Share on other sites

    Posted · Plugin help: Detecting when a model is added or deleted from the build platform

    Very interesting piece of code... @nallath is there any solution to detect if the geometry have changed . I was using in one of my plugin :

     

            self._scene = CuraApplication.getInstance().getController().getScene().getRoot() #type: Scene Root
            self._scene.meshDataChanged.connect(self._onSceneChanged)

     

    but it also detect if we change the position of the part position on the buildplate or any modification set on the meshData.

     

     

  • Link to post
    Share on other sites

    Posted · Plugin help: Detecting when a model is added or deleted from the build platform

    Not exactly what I'm looking for but jut a little step further.

     

        def _onSceneChanged(self, source: SceneNode) -> None:
            new_scene_objects = set(node for node in BreadthFirstIterator(self._scene) if node.callDecoration("isSliceable"))
            if new_scene_objects != self._scene_objects:
                Logger.log("d", "New_scene_objects")
                self.StandardFixed=0
            
            self._scene_objects = new_scene_objects  

     

  • 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

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