Jump to content
UltiMaker Community of 3D Printing Experts

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


bradk3
 Share

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
     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
        • 14 replies
    ×
    ×
    • Create New...