Based on the docs here, if I pass true to the second parameter when I am adding a selectionItem, selectionArray should not be triggered. It doesn’t get triggered if the node is not already in the selection. However, if I select I add it twice, it gets triggered…
We’ll create a support ticket on your behalf and have our Communicator development team take a closer look at the behavior.
One quick note is that for the second call that triggers the callback, it’s possible to “catch” the callback because the returned selection events array is empty:
hwv.setCallbacks({
selectionArray: function (selections) {
if (selections.length === 0) {
console.log("selections is empty");
} else {
//...
}
}
});
Thank for the quick reply Tino! We could check for the selections.length, but it’s not reliable in our case.
I’d like to also mention that doing viewer.selectionManager.selectNode(nodeNumber, Communicator.SelectionMode.Add); when the node is already selected yields an empty selectionArray also.
Another question:
Is there a way to intercept the selectionManager for nodes being added/removed/toggled? Like providing our own custom selectionManager which extends the original Hoops Communicator SelectionManager? We would like to perform some operations on nodes right before they are selected or unselected.
Triggered BEFORE a batch of incrementally selected entities is put into the SelectionManager
I also wanted to briefly mention the function setSelectionFilter. While this function does not pre-empt a selection operation, it can be handy if you want to quickly manipulate certain nodes. An example is provided in this forum post.
If this post doesn’t fully address the requirements of your particular workflow, we kindly request that you create a feature request via our Communicator Support Portal. Please include the necessary technical details to assist us in a more comprehensive evaluation.
What you mentioned doesn’t fully work for our use case, but it’s good to know that this is available. I think we will just track what we have selected or not through the selectionArray callback by checking the selectionManager and updating our tracker object.