【问题标题】:API Download File from BIM360 Doc Plans folder从 BIM360 Doc Plans 文件夹中的 API 下载文件
【发布时间】:2019-08-15 17:22:33
【问题描述】:

我正在尝试使用 Forge API 从 Autodesk BIM360 Doc (https://docs.b360.autodesk.com) 下载文件,以便随后将文件归档到我们的本地存储中。

我已经设法使用数据管理 API https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/"Project Files" 文件夹中下载任何文件,我可以使用它获取 data.relationships.storage 下的存储 ID。数据.id

但是使用相同的 API,我在查询 "Plan" 文件夹下的文件时无法获取存储 ID,

那么 Forge API 有什么方法可以让我们从 Plan 文件夹中下载文件吗?任何帮助表示赞赏。

【问题讨论】:

    标签: autodesk-forge autodesk-bim360


    【解决方案1】:

    Plan 文件夹中列出的项目是items:autodesk.bim360:Document 的类型,该类型项目在GET versions/:version_idGET items/:item_id 的响应中不会直接显示存储属性。

    要获取物理文件位置,您应该调用GET versions/:version_id/relationships/refs,类似的线程请参见此处:Download a Document with Autodesk API

    复制项目的更新

    当通过GET versions/:version_id/relationships/refs访问复制项的版本关系数据时,您会看到一个数据属性,以我的经验告诉复制项与源项之间的关系:

    "data": [
        {
            "type": "versions",
            "id": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
            "meta": {
                "refType": "derived",
                "fromId": "urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg?version=2",
                "fromType": "versions",
                "toId": "urn:adsk.wipprod:fs.file:vf.y3L7YbfAQJWwumMgqjJUxg?version=1",
                "toType": "versions",
                "direction": "to",
                "extension": {
                    "type": "derived:autodesk.bim360:CopyDocument",
                    "version": "1.0",
                    "schema": {
                        "href": "https://developer.api.autodesk.com/schema/v1/versions/derived:autodesk.bim360:CopyDocument-1.0"
                    },
                    "data": {}
                }
            }
        }
    ],  
    

    之后,你必须通过调用GET versions/:version_id/relationships/refs来访问fromId的版本关系数据。

    在这种情况下,它是{PROJ_ID}/versions/urn:adsk.wipprod:fs.file:vf.34Xvlw1jTcSQ_XkIVh07cg%3Fversion=2/relationships/refs,那么您将在我的调查中看到响应中的storage 属性。

    【讨论】:

    • 感谢您的快速回答,API GET versions/:version_id/relationships/refs 已经尝试过了,但是没有运气。 item的类型是derived:autodesk.bim360:CopyDocument,并且没有返回存储节点
    • 你能分享更多关于derived:autodesk.bim360:CopyDocument的细节吗?好像我以前没见过这个。您是如何创建这种类型的项目的?
    • 当文档被移动或复制到计划库下的不同文件夹时,w 会得到不同的项目类型,例如。 derived:autodesk.bim360:CopyDocumentderived:autodesk.bim360:FileToDocument,在我们的案例中,我们使用 BIM360 Docs 的审批工作流程将已批准的文件复制到阶段文件夹中,因此我们得到的 data.meta.extension.type 等于 derived:autodesk.bim360:CopyDocument
    • 我已经更新了答案,请试一试。它按预期从我身边工作。干杯
    • 感谢您的更新。是的,这解决了大部分情况。
    【解决方案2】:

    以防万一其他人遇到同样的问题,我发布了我最终设法获取文件存储信息的代码。但是,请随意提出其他方法,而不是对完整关系树进行迭代。

    internal static ForgeFileInfo getItemVersion(string token, string projectID, string versionID)
        {
            ForgeFileInfo forgeFileInfo = new ForgeFileInfo();
    
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            versionApi.Configuration.AccessToken = token;
            var version = versionApi.GetVersion(projectID, versionID);
            string fileType = version.data.attributes.extension.type;
            switch (fileType) {
                case "versions:autodesk.bim360:File":
                    //File from Project File library or is regual file
                    forgeFileInfo.FileName = version.data.attributes.displayName;
                    forgeFileInfo.FileLocation = version.data.relationships.storage.meta.link.href;
                    forgeFileInfo.StorageId = version.data.relationships.storage.data.id;
                    return forgeFileInfo;
                case "versions:autodesk.bim360:Document":
                    //File from Plan Library
                    var versionRelationship=versionApi.GetVersionRelationshipsRefs(projectID, versionID);
    
                    // the GET Relationship has data node where we can get the related document
                    var relationshipData = new DynamicDictionaryItems(versionRelationship.data);
                    // let's start iterating the relationship DATA
                    foreach (KeyValuePair<string, dynamic> relationshipItem in relationshipData)
                    {
                        //Have to loop until we found "derived:autodesk.bim360:FileToDocument"
                        var relationType = relationshipItem.Value.meta.extension.type;
                        var relation = relationshipItem.Value.meta.direction;
                        if ("derived:autodesk.bim360:FileToDocument".Equals(relationType))
                        {
                            if ("to".Equals(relation))
                            {
                                //Go up stream
                                return getItemVersion(token, projectID, relationshipItem.Value.id);
                            }
                        }
                        else if ("derived:autodesk.bim360:CopyDocument".Equals(relationType))
                        {
                            if ("to".Equals(relation))
                            {
                                //Go up stream
                                return getItemVersion(token, projectID, relationshipItem.Value.id);
                            }
                            continue;
                        }               
                    }
                    break;
            }
            return forgeFileInfo;
        }
    

    【讨论】:

      猜你喜欢
      • 2019-08-13
      • 1970-01-01
      • 2018-11-24
      • 2015-11-17
      • 2018-03-09
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多