2017-08-28 39 views
0

我得到這個錯誤:Uncaught TypeError:>無法讀取屬性'getRootId'的未定義 即使我使用Autodesk.Viewing.GEOMETRY_LOADED_EVENT ..仍然沒有效果。無法讀取instanceTree autodesk

+0

哪個版本觀衆正在使用?建議使用上面的v2.16,viewingService(View和Data API)現在已經過期。查看更多的細節,https://forge.autodesk.com/blog/viewer-giving-error-403-unauthorized –

回答

0

你只需要等待Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT被解僱的時候,你要訪問的instanceTree:中

viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function() { 

    var instanceTree = model.getData().instanceTree //cool 
}) 
+0

感謝這一個也是完美的工作。 –

0

您不應該使用instanceTree數據結構,但應該使用支持的功能/操作。如果你需要的是枚舉葉節點,嘗試類似的東西爲described here

function getAllLeafComponents(viewer, callback) { 
    var cbCount = 0; // count pending callbacks 
    var components = []; // store the results 
    var tree; // the instance tree 

    function getLeafComponentsRec(parent) { 
     cbCount++; 
     if (tree.getChildCount(parent) != 0) { 
      tree.enumNodeChildren(parent, function (children) { 
       getLeafComponentsRec(children); 
      }, false); 
     } else { 
      components.push(parent); 
     } 
     if (--cbCount == 0) callback(components); 
    } 
    viewer.getObjectTree(function (objectTree) { 
     tree = objectTree; 
     var allLeafComponents = getLeafComponentsRec(tree.getRootId()); 
    }); 
} 
+0

我已經通過簡單的黑客解決了它: –

+0

'function waitForElement(){ if(instanceTree.getRootId( )!==「undefined」){...} else { setTimeout(waitForElement,250); } };' –

+0

或'Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT'? –