I'm getting this error in console when I use viewer.start()
to start a Autodesk forge viewer when I'm trying to display Navisworks models (.nwd/.nwc files). For .rvt, .fbx, .3ds, and .max files everything seems OK.
GuiViewer3D.js:244 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'getNamedViews') at Object.addViews (GuiViewer3D.js:244:40) at SvfLoader.js:256:31
This error references the following in GuiViewer3D.js:
And although the viewer will launch, it won't show any model:
Here is my code:
const lunchViewer = (urn) => {
var options = {
env: 'AutodeskProduction',
getAccessToken: getForgeToken,
};
var documentId = 'urn:' + urn;
window.Autodesk.Viewing.Initializer(options, () => {
window.Autodesk.Viewing.Document.load(
documentId,
onDocumentLoadSuccess,
onDocumentLoadFailure
);
});
};
const onDocumentLoadSuccess = (doc) => {
const geometries = doc.getRoot().search({ type: 'geometry' });
if (geometries.length === 0) {
console.error('Document contains no geometries.');
return;
}
const viewerDiv = document.getElementById('viewer');
const config = {
extensions: [
'Autodesk.DocumentBrowser',
'Autodesk.Viewing.MarkupsCore',
],
};
const viewer = new window.Autodesk.Viewing.Private.GuiViewer3D(
viewerDiv,
config
);
const initGeom = geometries[0];
const svfUrl = doc.getViewablePath(initGeom);
const modelOptions = {
sharedPropertyDbPath: doc.getFullPath(
doc.getRoot().findPropertyDbPath()
),
};
viewer.start(
svfUrl,
modelOptions,
onLoadModelSuccess,
onLoadModelError
);
};
I'm using the above approach to be able to add multiple models in a same viewer. And also to switch between views in the same loaded model in the viewer.
This is a known issue, which has been fixed in viewer v7.93. Please try to upgrade it to v7.93 to see if it helps.
For older versions, please consider GuiViewer3D#loadDocumentNode instead.
Here is an example util demonstrating how to aggregate multiple models using GuiViewer3D#loadDocumentNode: