如何获得所选对象的数量?

时间:2018-10-29 12:38:34

标签: autodesk-forge

如何获取选定对象的数量,就像您在这里看到的那样:https://imgur.com/71Rm0Y4? @PetrBroz帮助我获取了所选对象的属性(他的示例在这里: ),但我还需要获取数量:https://imgur.com/71Rm0Y4
谢谢。

1 个答案:

答案 0 :(得分:0)

您需要遍历实例树来找到您感兴趣的父级。在您的示例中,将是这样的:

const ids = viewer.getSelection();
if (ids.length > 0) {
    const instanceTree = viewer.model.getData().instanceTree;
    let id = ids[0];
    id = instanceTree.getNodeParentId(id);
    id = instanceTree.getNodeParentId(id);
    id = instanceTree.getNodeParentId(id);
    // Or better, traverse the parents in a while loop until you find one that matches your requirements
    viewer.getProperties(id, function(props) {
        console.log(props);
    });
}