2

I'm using the Forge Viewer on an Angular 5 application.

Is there a way to completely unload the viewer so it can later be reloaded?

I have the following code to unload the viewer:

if (this.viewer && this.viewer.running) {
  this.viewer.tearDown();
  this.viewer.finish();
  this.viewer = null;
}

And I also have the code to load the viewer every time the user enters the page.

Currently, when a user navigates to a different page on the application, that code gets executed, but when the user comes back to the page that contains the viewer, it shows a grey box where the viewer should be.

Here's a github repo that reproduces the issue: https://github.com/theivanaguilar/forge-viewer-reload

Am I missing something here?

Ivan Aguilar
  • 565
  • 1
  • 7
  • 22

1 Answers1

2

The static method Autodesk.Viewing.Initializer can only be called once the subsequent times it will not return. All other viewer methods need to be invoked every time your component loads. So you need to refactor your code a bit.

My app is using React and I save a boolean in the appState to avoid calling that Initializer twice if it has been initialized already.

Hope that helps

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Felipe
  • 4,325
  • 1
  • 14
  • 19
  • Hi Phillipe, I have an application where I teardown the viewer and load a model again. It works but the problem is that the model's Id keeps on incrementing each time. I was expecting that after teardown, the ids would reset to 1. Why the viewer keeps the memory of how many viewers had been added to it before the teardown. What should I do to reset the Ids? Thanks.@Phillipe – ashish Jul 30 '19 at 15:10
  • Yeah I would expect it to be reset as well... I no longer work at adsk, so I would advise you to ask dedicated support, my answer will be very brief :) It's too little context info about your workflow to give a more precise advice, but first you can unload models without completely teardown the viewer, and second I would not rely on the model ids generated by the API for anything, instead upon loading of a new model, you can use API events to set your own guid or whatever data you want to attach to the model object. Cheers! – Felipe Jul 30 '19 at 16:28
  • Hi Philippe, Thanks for your inputs. We are trying the approach of setting our own ids. I hope it will work. – ashish Jul 31 '19 at 07:53
  • This definitely work, using that since a long time. I grab the model in the "Autodesk.Viewing.MODEL_ROOT_LOADED_EVENT", and do something as simple as model.myId = "unique-guid" – Felipe Jul 31 '19 at 08:26