I have created an onSelection changed method as per the tutorial set out here: Selection Override
i have set this up for multi-selection as well which works well.
However when I try to deselect a group selected component it doesn't trigger the onSelectionChange event as I have it coded (shown below). The method is never triggered.
But if I comment out this line:
viewerApp.getCurrentViewer().select(idsToSelect);
Then the toggle of selected components works perfectly. And triggers the onSelectionChnge event.
Any help? Is there an alternative to doing methods after the slection has changed? Possibly when a part is clicked?
The code looks like this:
viewerApp.getCurrentViewer().addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged);
function onSelectionChanged(data) {
console.log("selection changed event. Selected dbIds are: " + data.dbIdArray.toString());
if (data.dbIdArray.length > 0 && data.fragIdsArray.length > 0) {
var idsToSelect = [];
var selectionChanged = false;
for (var k = 0; k < data.dbIdArray.length; k++) {
var dbId = data.dbIdArray[k];
if (leafNodes.indexOf(dbId) > -1) {
dbId = viewerApp.getCurrentViewer().model.getData().instanceTree.nodeAccess.getParentId(dbId);
selectionChanged = true;
}
idsToSelect.push(dbId);
}
if (selectionChanged) {
viewerApp.getCurrentViewer().select(idsToSelect);
}
}
}