MrD
MrD

Reputation: 1275

Autodesk Forge Viewer: Selection-event not working anymore after adding a custom model

I am working on the example from Custom models in Forge Viewer blog entry from Petr Broz.

The problem I am facing at the moment is, that the Autodesk.Viewing.SELECTION_CHANGED_EVENT event is not raised any more after calling the sceneBuilder.addNewModel method. To test the issue i've modified the Codepen-example:

Add a new function:

function onSelection(event) {
    event.dbIdArray.forEach(selection => {
        console.log(`selected ${selection}`)
    });
}

...and register the function as event listener (as first step in the setup):

[...]
forgist.setup(document.getElementById('viewer'), 2).then(viewer => {
    viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelection)
    [...]

As long as I don't click the "Add geometry" button, the selection is shown in the console, but afterwards nothing is printed.

edit: the viewer.getSelection() method still returns the correct id of the selected objects

Upvotes: 0

Views: 951

Answers (1)

Adam Nagy
Adam Nagy

Reputation: 2175

In case of creating a multi model environment, you would have to use AGGREGATE_SELECTION_CHANGED_EVENT to be notified about selections

Upvotes: 2

Related Questions