简体   繁体   中英

How to change object names in Forge Viewer?

How can I change the names of objects and parent nodes in Forge Viewer?

In version 6.1 and below, there was a blog post that worked: by altering the ModelStructureTreeDelegate class, reloading it as an extension, effectively overriding it. That doesn't work on 6.2 and later (current is 6.3.3), because now that class is not accessible anymore, or otherwise doesn't work.

What I found was that, by accessing the InstanceTreeStorage.prototype.processName method, I could change the name of objects in the tree, but that class is not available externally. It seems to be used only during Model loading.

I found no other class that changes the name, or any other function that lets me do it.

Has anyone done something similar with the most recent version of the Viewer?

You can create your own model structure panel by deriving from the Autodesk.Viewing.Extensions.ViewerModelStructurePanel class, overriding the getNodeLabel method, and setting an instance of the class as the model structure UI for the viewer:

class CustomModelStructurePanel extends Autodesk.Viewing.Extensions.ViewerModelStructurePanel {
    constructor(viewer, title, options) {
        super(viewer, title, options);
    }

    getNodeLabel(node) {
        return 'custom node name';
    }
}

viewer.setModelStructurePanel(new CustomModelStructurePanel(viewer, 'Custom Model Structure', options));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM