0

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);
            }
        }

    }
Neil_M
  • 462
  • 5
  • 17
  • Where does your `leafNodes` come from and what is it for? I couldn't find it from your code snippet. And would you mind explaining what does the `a group selected component` mean? Does it stand for "A group of selected components that are picked up by the `ctrl + mouse clicking`"? – Eason Kang Oct 16 '17 at 03:26
  • LeafNodes is an array that is generated from using the method setout in the anser to this question: https://stackoverflow.com/questions/45837361/setthemingcolor-only-working-for-leaf-node-dbids – Neil_M Nov 01 '17 at 14:28
  • Yes @EasonKang , "group of selected components that are picked up by the ctrl + mouse clicking" is what I was trying to say. So the issue I have is once I use Ctrl+Click to select multiple components, then if i want to remove one from the group I want to be able to Ctrl+Click on that component and it should be removed from the selected group and the seletion changed event should be triggered. However in my example above that doesn't happen. – Neil_M Nov 01 '17 at 14:36

0 Answers0