Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...