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

如何在Autodesk Viewer中获取链接文档的层级结构?

获取Revit嵌套链接文档的层级结构(Autodesk Viewer)

别再盯着linkedDocuments返回的扁平列表了——要拿到链接文档的嵌套层级,直接遍历Viewer的文档节点树就行,每个链接节点都能找到它的父节点归属。

实现思路

从根文档节点出发,递归遍历所有子节点:

  • 用isLinkNode()判断节点是否为链接文档
  • 记录每个文档的ID、名称,以及它的父文档ID,以此构建层级关系

代码示例

async function buildLinkedDocHierarchy() {
    const rootNode = NOP_VIEWER.model.getDocumentNode();
    const hierarchy = [];

    // 递归遍历节点树,parentId标记父文档的GUID
    async function traverse(node, parentId) {
        const doc = await node.getDocument();
        const docInfo = {
            guid: doc.guid,
            name: doc.name,
            parentId: parentId,
            children: []
        };
        hierarchy.push(docInfo);

        // 遍历当前节点的所有子节点
        for (const child of node.getChildren()) {
            if (child.isLinkNode()) {
                const childDoc = await traverse(child, doc.guid);
                docInfo.children.push(childDoc.guid);
            }
        }
        return docInfo;
    }

    await traverse(rootNode, null);
    return hierarchy;
}

// 调用后就能拿到带层级的结构
buildLinkedDocHierarchy().then(hierarchy => {
    console.log('层级结构:', hierarchy);
});

效果示例

对应你提到的「A包含B、C,B包含D」的场景,返回的结构会是这样:

[
    {
        "guid": "A的GUID",
        "name": "文档A",
        "parentId": null,
        "children": ["B的GUID", "C的GUID"]
    },
    {
        "guid": "B的GUID",
        "name": "文档B",
        "parentId": "A的GUID",
        "children": ["D的GUID"]
    },
    {
        "guid": "C的GUID",
        "name": "文档C",
        "parentId": "A的GUID",
        "children": []
    },
    {
        "guid": "D的GUID",
        "name": "文档D",
        "parentId": "B的GUID",
        "children": []
    }
]

这样就能明确区分每个链接文档的层级了,再也不会把D当成A的直接链接。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 05:04:52