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

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