Reputation: 313
When viewing files in Autodesk forge viewer, getting some errors like • “Cannot read property ‘setEndpoint’ of undefined” • “doc.getRootItem is not a function” And will be able to view after hard reload (Ctrl + Shift +R) the page. Sometimes the same errors will get again even after hard reload and clear cache the browser.
var options = {
env: 'AutodeskProduction',
accessToken: getAccessToken() //Method to get access token- no errors here
};
var documentId = 'urn:' + urn;
Autodesk.Viewing.Initializer(options, function onInitialized() {
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
//Autodesk.Viewing.Document.load - success function.
function onDocumentLoadSuccess(doc) {
setTimeout(function() {
debugger;
}, 5000);
//Error is thrown in the line below.
var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
'type': 'geometry'
}, true); //throws error on calling doc.getRootItem()
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the avialble viewables
var initialViewable = viewables[0];
var svfUrl = doc.getViewablePath(initialViewable);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath()
};
var viewerDiv = document.getElementById('divViewer');
viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
}
Upvotes: 1
Views: 123
Reputation: 5342
After upgrading to Viewer v7 pls use doc.getRoot()
- doc.getRootItem()
has been deprecated:
NOP_VIEWER.loadDocumentNode(doc, doc.getRoot().getDefaultGeometry());
See live sample here and migration guide to v7 here.
Upvotes: 1