I need to change the selection mode for IFC models in Autodesk Viewer from “First Object” (value 1) to either “Leaf Object” or “Last Object” (0 or 2).
I have encountered multiple problems:
While other configuration parameters like viewCube can be modified programmatically using the profiles API, selectionMode seems to only change correctly when using the HTML interface.
Using the following code, the viewCube setting changes correctly, but the selectionMode does not:
let defaultCustomProfile = Autodesk.Viewing.ProfileSettings.Default;
let customProfileSettings = Autodesk.Viewing.ProfileSettings.clone(defaultCustomProfile);
customProfileSettings.settings.selectionMode = 2;
customProfileSettings.settings.viewCube = false;
const customProfile = new Autodesk.Viewing.Profile(customProfileSettings);
viewer.profileManager.registerProfile('Default', customProfile);
viewer.setProfile(customProfile);
Manually clicking the selectionMode option in the config panel, so that the viewer loads with that option from the saved config when reloading the viewer, does not always work. While the config panel shows the correct option is selected, the viewer sometimes functions as if “First Object” mode is still in effect. I have not been able to find a correlation as to why it works sometimes and not others.
Currently, the only option I have found that seems to work consistently is this workaround:
let intervalId = setInterval(function() {
let dropdown = document.getElementById("Selection Mode_dropdown");
if (dropdown) {
dropdown.selectedIndex = 1;
dropdown.dispatchEvent(new Event('change'));
dropdown.selectedIndex = 0;
dropdown.dispatchEvent(new Event('change'));
clearInterval(intervalId);
}
}, 500);
While this solution works perfectly, it is far from ideal as it is just a band-aid fix. I would like to know if there is a proper way to change selectionMode that will work
Also, is there somewhere I can read about the differences between “Leaf Object” and “Last Object”? From what I can see, they both appear to be the same.