Reputation: 4424
I tried to unload extension in Viewer from Autodesk, I call extension inside the callback from Viewing.Initializer, but it seems to Extensions in this part of code is not loaded yet.
var viewer;
var options = {
env: 'AutodeskProduction',
api: 'derivativeV2', // for models uploaded to EMEA change this option to 'derivativeV2_EU'
// Function to define the method to get the token and renew it
getAccessToken: function (onTokenReady) {
let token = '';
let timeInSeconds = 3600; // TODO: Use value provided by Forge Authentication (OAuth) API
// Code to get my token and time remaining
onTokenReady(token, timeInSeconds);
}
};
/**
* Initializer function, when load the viewer
*/
Autodesk.Viewing.Initializer(options, function () {
// Extensions
var config3d = {
extensions: ['forgeExtension', 'EventsTutorial', 'Autodesk.DocumentBrowser'],
};
// The dom element, where load the viewer
var htmlDiv = document.getElementById('forgeViewer');
viewer = new Autodesk.Viewing.GuiViewer3D(htmlDiv, config3d);
//
// Here I want to unload 'Autodesk.Explode'
let explodeExtension = viewer.getExtension('Autodesk.Explode'); // explodeExtension is null
explodeExtension.unload();
//
//
var startedCode = viewer.start();
if (startedCode > 0) {
console.error('Failed to create a Viewer: WebGL not supported.');
return;
}
console.log('Initialization complete, loading a model next...');
});
Any suggestion to unload a deafult Extension? I´m using V7 viewer, I tried in V6 with the same result.
Upvotes: 1
Views: 1099
Reputation: 662
You can use viewer events to make sure the extensions are there and can be unloaded. Your unloading code is correct you just need to wait for the full geometry to load. Using this viewer event you can unload the default extentions when the geometry is loaded
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) => {
let explodeExtension = viewer.getExtension('Autodesk.Explode'); /
explodeExtension.unload();} );
This will unload the extension as soon as it loads.
Alternativly you could prevent the extension from being loaded at all by unregistering it. Autodesk.Viewing.theExtensionManager.unregisterExtension('Autodesk.Explode');
This would result in an error tho since the viewer is still trying to load the extensions but the viewer will still work as expected.
Upvotes: 4