September 13, 2017

Selection override

When clicking on objects in the Viewer, always the leaf node will be selected. 

In many models the components will have a child called "Body", or "Solid", etc, and often those are not the objects with the properties you are interested in. That makes it difficult for the user to get quickly at the data they need.

Fortunately, you can easily write a function that would override the selection to select the parent of the given object. You just have to listen to the Autodesk.Viewing.SELECTION_CHANGED_EVENT event and modify the selection:

    // ...
    oViewer =new Autodesk.Viewing.Private.GuiViewer3D ($("#viewer") [0], {});
    oViewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged)

function onSelectionChanged(event) {
    // Let's only control selection in case of
    // single user selection
    if (event.dbIdArray.length === 1) {
        oViewer.getProperties(event.dbIdArray[0], function(data) {
            if ("Solid")) {
                var instanceTree = oViewer.model.getData().instanceTree;
                var parentId = instanceTree.getNodeParentId(event.dbIdArray[0])

Now when clicking on the object, the parent gets selected which has all the properties we need:

Selecting the parent instead

Related Posts

July 11, 2019

New Autodesk Forge Viewer 7.0 is Now Available

Autodesk Forge is our collection of Application Program Interfaces (APIs), documentation, sample code, and a community of cust

Read More

July 10, 2019

Look for exact property value and more

When using the search() function of the Viewer, you can only look for strings that at least partially match a given value.

Read More

July 9, 2019

Webpack and three.js in forge applications

In the newer versions of forge viewers( v6 and above) three.js is included in the forge viwer js file itself.

Read More