我可以通过以下方式获取查看器中所有项目的 dbId
const tree = viewerApp.myCurrentViewer.model.getData().instanceTree;
const dbIndices = Object.values(tree.nodeAccess.dbIdToIndex).slice(1);
但对于从 Revit 导入的模型,其数量远大于查看器中实际可见的对象(例如,对于仅由三堵墙组成的项目,该数量约为 3,500)。如何获取仅可见对象的 dbId?
最佳答案
默认情况下,加载模型时所有节点(为查看器渲染的资源)都是可见的。除了与 Revit 组件的 UniqueID
相对应的 externalId
之外,每个节点还可以通过唯一的 dbid
进行唯一标识。
因此您观察到的额外 dbids
实际上是父节点。要隔离它们,请参阅 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());
});
}
关于javascript - 如何获取Viewer中仅可见对象的dbId?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55135410/