2017-08-28 40 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'? –