You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

APS/Forge Viewer如何获取仅已加载元素的dbid?

如何在Autodesk Viewer中高效获取实际已加载元素的DBID?

当Viewer启用选择性加载时,getVisibleDbIds()会返回所有标记为可见的元素(包括未加载的),要只获取实际已加载的元素DBID,最高效的方式是直接调用Viewer模型内部维护的已加载DBID集合:

  • 直接访问模型的loadedDbIds属性,这是Viewer实时维护的数组,无需额外遍历或判断,性能最优。

代码示例:

// 获取当前Viewer中激活的模型
const activeModel = viewer.model;
// 直接获取已加载元素的DBID数组
const loadedDbIds = activeModel.getData().loadedDbIds;
// 输出结果
console.log('已加载元素DBID列表:', loadedDbIds);

如果你的Viewer版本较旧,loadedDbIds属性不可用,可以通过遍历节点并判断加载状态的方式实现,但效率稍低:

const activeModel = viewer.model;
const instanceTree = activeModel.getData().instanceTree;
const loadedDbIds = [];

// 遍历根节点下的所有元素
instanceTree.enumNodeChildren(instanceTree.getRootId(), (dbid) => {
    // 判断当前元素是否已加载
    if (instanceTree.isNodeLoaded(dbid)) {
        loadedDbIds.push(dbid);
    }
}, true);

console.log('已加载元素DBID列表:', loadedDbIds);

核心逻辑说明:

  • 选择性加载模式下,元素的「可见性」和「加载状态」是两个独立的属性,getVisibleDbIds()只判断可见性,而loadedDbIds直接对应实际已加载到Viewer实例中的元素。
  • 优先使用第一种方法,因为loadedDbIds是Viewer内部维护的缓存集合,不需要额外计算,性能远高于遍历判断。

内容的提问来源于stack exchange,提问作者TD123123123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 15:42:07