Reputation: 37
I am getting this error: Uncaught TypeError:> Cannot read property 'getRootId' of undefined even i am using Autodesk.Viewing.GEOMETRY_LOADED_EVENT..still no effect.
Upvotes: 0
Views: 415
Reputation: 4375
You just need to wait for Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT
to be fired when you want to access the instanceTree
:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
var instanceTree = model.getData().instanceTree //cool
})
Upvotes: 2
Reputation: 8574
You should not be using instanceTree
data structure, but yet the functions/operations, which are the supported way. If your need is to enumerate leaf nodes, try something similar to as 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());
});
}
Upvotes: 0