# Calling selectionManager.add with suppressCallback to be true, still triggers selectionArray callback

**URL:** <https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192>\
**Category:** HOOPS Visualize Web\
**Tags:** webviewer\
**Created:** [January 23, 2024, 8:52pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192 "2024-01-23T20:52:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.aronin](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mark.aronin](https://forum.techsoft3d.com/u/mark.aronin)\
**Post date:** [January 23, 2024, 8:52pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192/1 "2024-01-23T20:52:03Z")

</div>

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…

[https://docs.techsoft3d.com/communicator/latest/api\_ref/viewing/classes/Communicator.SelectionManager.html](https://docs.techsoft3d.com/communicator/latest/api_ref/viewing/classes/Communicator.SelectionManager.html)

1. run `viewer.selectionManager.add([Communicator.Selection.SelectionItem.create(nodeNumber)], true)`
2. `selectionArray` callback on `webViewer` doesn’t get called
3. Then run the same line again
4. `selectionArray` callback on `webViewer` gets triggered

Is this intentional or a bug?

Thank you!

---

<div class="post-metadata">

**Author:** ![tino](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tino](https://forum.techsoft3d.com/u/tino)\
**Post date:** [January 24, 2024, 1:36pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192/2 "2024-01-24T13:36:42Z")

</div>

Hello @mark.aronin,

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:

```auto
hwv.setCallbacks({
        selectionArray: function (selections) {
		if (selections.length === 0) {
			console.log("selections is empty");
		} else {
		//...
        }
	}
});

```

Thanks,  
Tino

---

<div class="post-metadata">

**Author:** ![mark.aronin](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mark.aronin](https://forum.techsoft3d.com/u/mark.aronin)\
**Post date:** [January 24, 2024, 2:44pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192/3 "2024-01-24T14:44:15Z")

</div>

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.

Thanks again!

---

<div class="post-metadata">

**Author:** ![tino](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tino](https://forum.techsoft3d.com/u/tino)\
**Post date:** [January 25, 2024, 2:05pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192/4 "2024-01-25T14:05:05Z")

</div>

Hello @mark.aronin,

A callback that could be helpful is [incrementalSelectionBatchBegin](https://docs.techsoft3d.com/communicator/latest/api_ref/viewing/interfaces/Communicator.CallbackMap.html#Communicator.CallbackMap.incrementalSelectionBatchBegin) (and complimentary callbacks [incrementalSelectionBatchEnd](https://docs.techsoft3d.com/communicator/latest/api_ref/viewing/interfaces/Communicator.CallbackMap.html#Communicator.CallbackMap.incrementalSelectionBatchEnd) and [incrementalSelectionEnd](https://docs.techsoft3d.com/communicator/latest/api_ref/viewing/interfaces/Communicator.CallbackMap.html#Communicator.CallbackMap.incrementalSelectionEnd)). As stated in our docs, `incrementalSelectionBatchBegin` is

> Triggered BEFORE a batch of incrementally selected entities is put into the `SelectionManager`

I also wanted to briefly mention the function [setSelectionFilter](https://docs.techsoft3d.com/communicator/latest/api_ref/viewing/classes/Communicator.SelectionManager.html#Communicator.SelectionManager.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](https://forum.techsoft3d.com/t/how-to-use-setselectionfilter/1333).

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](https://techsoft3d.atlassian.net/servicedesk/customer/portal/12). Please include the necessary technical details to assist us in a more comprehensive evaluation.

Thanks,  
Tino

---

<div class="post-metadata">

**Author:** ![mark.aronin](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@mark.aronin](https://forum.techsoft3d.com/u/mark.aronin)\
**Post date:** [January 25, 2024, 2:44pm UTC](https://forum.techsoft3d.com/t/calling-selectionmanager-add-with-suppresscallback-to-be-true-still-triggers-selectionarray-callback/3192/5 "2024-01-25T14:44:35Z")

</div>

Thanks Tino!

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.

Thanks again for all your support!
