Best way to handle dzScene->primarySelectionChanged() ?

Vholf3DVholf3D Posts: 63

I've noticed that primarySelectionChanged() (and also nodeSelectionListChanged) gets triggered several times on a single select operation. I can see the nodes are selected and deselected and then selected again (alghough, for some reason node->isSelected() is always true).

What is the expected way to handle this event? I need to do some selection operations on the actual "scene->getPrimarySelection()", but the primary selection gets switched around in the process and I can't find a reliable flag to check.

I have tried to keep track of the selection stack, but I can't figure out a pattern, it goes from current to null to current and back again, and it gets worse when you select multiple nodes at once. There must be a proper way to handle it, any advice is very much welcome.

Post edited by Vholf3D on

Comments

  • Vholf3DVholf3D Posts: 63
    edited July 2022

    Some more experimenting and it seems that if I select nodes using the Viewport, each node selection event is fired once, but if I select it using the Scene tab (HierarchyPane) the node selection event is fired twice. I don't know if this is the expected behaviour but it is definitely a problem for what I intend to do.

    If I select a single node, I need to catch the node once all other nodes have been deselected, and if I select several, I need to get the list of nodes once all have been selected (as opposed to the nodeSelectionList growing on every call)

    Post edited by Vholf3D on
  • Vholf3D said:

    Some more experimenting and it seems that if I select nodes using the Viewport, each node selection event is fired once, but if I select it using the Scene tab (HierarchyPane) the node selection event is fired twice. I don't know if this is the expected behaviour but it is definitely a problem for what I intend to do.

    If I select a single node, I need to catch the node once all other nodes have been deselected, and if I select several, I need to get the list of nodes once all have been selected (as opposed to the nodeSelectionList growing on every call)

    Would be interested if you find any solution as I'm running into a similar issue.

    In my case, the selection changed event fires before a node is fully loaded and appears in the scene tab. The node's empty if I try to do anything on the first call, but I wish to save outputs from some custom node processing I do in order to save the expense of doing it on every selection change. I've seen as many as 4 events fired when a node is first loaded, but I haven't figured out a way to test if the event is the last one and can be used to trigger my expensive processing. Triggering it too early means the processing fails.

    I found the custom node properties sample works fine, but that it triggers many times and my expensive processing can become even more expensive because of the number of times it's triggered by using that pattern.

Sign In or Register to comment.