autodesk-forgeautodesk-viewerautodesk-data-visualization

Loading back extensions after changing models for Forge Viewer


Currently, I am implementing a Viewer Application that makes use of the angular wrapper from https://github.com/theNBS/ng2-adsk-forge-viewer

I managed to get the viewer set up, created and loaded several extensions from the DataVisualisation SDK.

However, whenever I change between models, the extensions get unloaded and I get this error.

Error

// Updates the model to be displayed in the viewer 
public triggerDocumentChange() { 
    this.modelService.selectedModelUrn = this.selectedModel.urn; 
    this.viewerComponent.DocumentId = this.urnify(this.selectedModel.urn); 
}

Steps I've tried:

  1. Reloading and registering the extensions whenever a document is loaded
this.viewer.addEventListener( 
  Autodesk.Viewing.GEOMETRY_LOADED_EVENT, 
    async () => { 
    // Initialize our data view with the modelService to help change the sensor values 
    const dataView = new MyDataView(this.modelService, 
       this.viewer); 
    await dataView.init({ 
    start: new Date("2022-01-01"), 
    end: new Date("2022-01-30"), 
}); 
this.reRegisterAndLoadExtensions(); 
 
// Get the instance of the registered extensions from the viewer
const extensions = this.getExtensionsInstance(); 
for (const ext of extensions) { // This is where the error is!
    console.log("Loaded extension: " + ext); 
    ext.dataView = dataView; 
    ext.activate(); 
} 

Any help would be greatly appreciated!


Solution

  • Resolved! The main issue was due to asynchronous nature of loading extensions onto the viewer.

    So whenever the model changed, the extensions did not have sufficient time to load back up before being used by the viewer. Causing the NullPointerException!