FlorolF
FlorolF

Reputation: 29

Apply built-in extension buttons to custom toolbar

i am looking for a way to display forge-viewer buildin extension buttons in another toolbar. E.g. Autodesk.DocumentBrowser or Autodesk.LayerManager.

I found a way to to add the control-button to the custom toolbar by asking for the control-id in Autodesk.Viewing.UI.ControlGroup.Event.CONTROL_ADDED event, remove the control from the original toolbar and add it to anthoer. But when i do this, some functions from the control-button are no longer available.

E.g. when i load the Autodesk.DocumentBrowser in another toolbar, i am able to use it as usual. But after switching viewables, the contorl-button stays activated for ever. The panel toggels after pressing the button, but the button stays activated.

I also tried to pass options to this method, but this does not affect anything:

viewer.loadExtension("Autodesk.DocumentBrowser",{parentControl:"custom-toolbar"})

Is there a better way to achieve this? Any ideas?

Upvotes: 0

Views: 283

Answers (1)

Petr Broz
Petr Broz

Reputation: 9942

Unfortunately the built-in viewer extensions do not provide any configuration as to which toolbar their buttons should be added to. Moreover, the extensions will often reference the main toolbar (this.viewer.toolbar) throughout their code, so even if you moved their buttons into another toolbar manually, you would very likely start running into all sorts of strange behaviors.

I believe the safest approach would be to create new toolbar buttons entirely, and try and reuse as much of the extension's functionality as possible. For example, in case of the Autodesk.DocumentBrowser extension, you could try and subclass the DocumentBrowser class, and override the UiController object it uses internally to add the toolbar UI. Of course, this will require more or less effort depending on how the extension is implemented.

Upvotes: 3

Related Questions