我们在 Revit 模型查看器中使用 Autodesk.AEC.LevelsExtension。但是在更改 Revit 视图(或几何图形)后,它会抛出错误。
这就是我们实现 LevelsExtension 的方式:
const initViewer = () => {
return new Promise((resolve, reject) => {
var options = {
env: 'AutodeskProduction2',
api: 'derivativeV2_EU',
getAccessToken,
};
Autodesk.Viewing.Initializer(options, () => {
const config = {
extensions: [
'Autodesk.DocumentBrowser',
'Autodesk.AEC.LevelsExtension',
],
};
const container = document.getElementById('viewer');
const viewer = new Autodesk.Viewing.GuiViewer3D(
container,
config
);
viewer.start();
resolve(viewer);
});
});
};
const loadModel = (viewer, model, index) => {
const onDocumentLoadSuccess = (doc) => {
const geometries = doc.getRoot().search({ type: 'geometry' });
doc.downloadAecModelData();
viewer.loadDocumentNode(doc, geometries[index], {
createWireframe: false,
applyScaling: 'm',
isAEC: true,
});
};
Autodesk.Viewing.Document.load(
'urn:' + model.urn,
onDocumentLoadSuccess,
onDocumentLoadFailure
);
};
正如您在更改视图之前所看到的,级别面板有一个
div
和 id="LevelsPanel-0"
:
感谢您的详细信息。即使不使用您的代码,我也可以重现此问题。我向我们的工程团队报告以获得见解。对于给您带来的不便,我们深表歉意!
这里有一个解决方法,我们在加载新模型之前删除levelsPanel。
viewer.getExtension('Autodesk.AEC.LevelsExtension').levelsPanel?.setVisible(false);
viewer.getExtension('Autodesk.AEC.LevelsExtension').levelsPanel?.container.remove();
const loadModel = (viewer, model, index) => {
const onDocumentLoadSuccess = async (doc) => {
if (viewer.getExtension('Autodesk.AEC.LevelsExtension')) {
viewer.getExtension('Autodesk.AEC.LevelsExtension').levelsPanel?.setVisible(false);
viewer.getExtension('Autodesk.AEC.LevelsExtension').levelsPanel?.container.remove();
}
const geometries = doc.getRoot().search({ type: 'geometry' });
doc.downloadAecModelData();
viewer.loadDocumentNode(doc, geometries[index], {
createWireframe: false,
applyScaling: 'm',
isAEC: true,
});
};
onDocumentLoadFailure = (error) => console.error(error);
Autodesk.Viewing.Document.load(
'urn:' + model.urn,
onDocumentLoadSuccess,
onDocumentLoadFailure
);
};