【问题标题】:Error in viewing files in Autodesk forge viewer - error calling doc.getRootItem()在 Autodesk forge 查看器中查看文件时出错 - 调用 doc.getRootItem() 时出错
【发布时间】:2019-11-15 20:43:59
【问题描述】:

在 Autodesk forge 查看器中查看文件时,出现以下错误,

  1. 无法读取未定义的属性 ‘setEndpoint’Screenshot

  2. doc.getRootItem 不是函数。 Screenshot

并且将能够在清空缓存和硬重新加载(Ctrl + Shift +R)后查看页面。有时,即使在硬重新加载和清除浏览器缓存后,同样的错误也会持续存在。

第二个错误的代码。

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);
}

【问题讨论】:

    标签: autodesk-forge autodesk forge


    【解决方案1】:

    您必须在不知情的情况下升级到 Viewer V7,其中 getRootItem 和其他几个功能已被弃用 - 请参阅 here 以获取其发行说明和迁移指南。

    使用<script src="https://developer-stg.api.autodesk.com/modelderivative/v2/viewers/viewer3D.js?v=6.6"></script> 坚持使用V6 - 如果您不指定默认版本,则将提供最新的稳定版本,即现在的V7.0。

    【讨论】:

      猜你喜欢
      • 2020-10-22
      • 2017-01-07
      • 2020-11-20
      • 2018-09-26
      • 2020-10-27
      • 2021-11-12
      • 1970-01-01
      • 2019-04-17
      • 2022-01-03
      相关资源
      最近更新 更多