2

I'd like to remove some buttons from the Forge Toolbar.

So far I've used the code by @Philippe at PhilippeAnswer and I successfully removed all the buttons in the 'navTools' and 'modelTools'. When trying with the 'settingsTools' I can remove only the ModelBrowser button, not the Properties or Settings or Fullscreen button (in debug mode I see these controls as null values). Here is my code:

var viewerDiv = document.getElementById('MyViewerDiv');
viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
const onExtensionLoaded = (e) => {
    if (e.extensionId === 'Autodesk.DefaultTools.NavTools') {
        const settingsTools = viewer.toolbar.getControl('settingsTools')
        settingsTools.removeControl('toolbar-modelStructureTool') //That's ok!

        settingsTools.removeControl('toolbar-propertiesTool')  //NOT FUNCTIONING          
        const settingsButton = settingsTools.getControl('toolbar-propertiesTool') //It remains as null when debugging
        settingsTools.removeControl(settingsButton)

        settingsTools.removeControl('toolbar-settingsTool') //NOT FUNCTIONING          

        settingsTools.removeControl('toolbar-fullscreenTool') //NOT FUNCTIONING          

        viewer.removeEventListener(
            Autodesk.Viewing.EXTENSION_LOADED_EVENT,
            onExtensionLoaded)
    }
} 
viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, onExtensionLoaded)
viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);

I know I can hide the entire settingsTool, but then I have the same problem when making visible to true for Property/Settings/Fullscreen button. It seems again the control remains null when debugging the code.

Please, can you help me facing with the 3 last buttons in the 'settingsTools' toolbar? Essentially, I'm trying to understand the global customization of the viewer, removing everything in the UI is not my purpose :)

Thanks!!

duffra
  • 45
  • 5
  • I prefer to just use the `.css` as it seems to be more stable between versions `.adsk-viewing-viewer #toolbar-settingsTool{display:none!important}` – Prageeth Jayathissa Nov 12 '19 at 09:19

1 Answers1

0

When to remove a specific button depends on whether at all it's created by an extension, and if so, which extension.

The "toolbar-firstPersonTool" button that Philippe's answer talks about is created by "Autodesk.FirstPerson" extension so we can just listen to the loading of that extension.

However, the buttons you are interested in, like "toolbar-modelStructureTool" are "built-in" and not created by an extension. So you have to listen to another event, the "TOOLBAR_CREATED_EVENT" as shown by this blog post: When to remove toolbar buttons

Adam Nagy
  • 1,700
  • 1
  • 9
  • 14
  • Thanks a lot! Just one more question: which is the js file opened in the screenshot in your blog post, where you highlight the GuiViewer3D.prototype.initModelTools function? It's very useful to understand the real behaviour of the viewer – duffra Mar 11 '19 at 09:48
  • [https://developer.api.autodesk.com/modelderivative/v2/viewers/6.*/viewer3D.js](https://developer.api.autodesk.com/modelderivative/v2/viewers/6.*/viewer3D.js) You can reference that instead of the min version from your html page – Adam Nagy Mar 11 '19 at 13:01