Search code examples
autodesk-forgeautodesk-viewer

Get Property Name of Part that is Selected


I am currently making a web page that uses the forge viewer. How can I make a function that will return the value from the "Properties" tab inside the viewer. I need to be able to get the value of the 'name' property inside the viewer, when a part is selected by the user. Any help is much appreciated! Cheers!


Solution

  • viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, onSelectionChanged)
    function onSelectionChanged(dbids){
        console.log(dbids)
        viewer.getProperties(dbIds, props => {
            props.properties.forEach(prop => {
                // any custom action with data?
                //prop.displayName 
                //prop.displayValue
                //prop.displayCategory
                // etc
            });
    }
    

    Blog: https://forge.autodesk.com/blog/property-inspector-viewer