You need to enable JavaScript to run this app. 如何在Autodesk Forge Viewer中获取当前文档节点?
优惠活动
大模型
产品
解决方案
定价
更多

如何在Autodesk Forge Viewer中获取当前文档节点?

从NOP_VIEWER获取当前展示文档节点的name和guid方法

场景1:获取当前加载的整个文档的根节点属性

直接调用文档节点接口即可拿到对应属性:

const docNode = NOP_VIEWER.model.getDocumentNode();
const currentNodeName = docNode.name;
const currentNodeGuid = docNode.guid;

场景2:获取用户当前选中的单个文档节点属性

先通过选择接口拿到选中节点ID,再查询对应属性即可:

// 获取选中的节点ID列表
const selectedNodeIds = NOP_VIEWER.getSelection();
if (selectedNodeIds.length > 0) {
  // 取第一个选中节点查询属性
  NOP_VIEWER.getProperties(selectedNodeIds[0], (res) => {
    const currentNodeName = res.name;
    const currentNodeGuid = res.externalId;
  })
}

注意:请确保调用方法时模型已经完成加载,避免拿到空值。可以将逻辑绑定到MODEL_LOADED事件中保证执行时机正确:

NOP_VIEWER.addEventListener(Autodesk.Viewing.MODEL_LOADED, () => {
  // 你的属性获取逻辑放在这里
})

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 20:36:06