September 24, 2019

BIM360 Docs: Setting up external references between files (Upload Linked Files)

 

Model Derivative API has the ability to translate composite models (i.e. multiple models linked by the xRefs or external links) into a single Forge Viewer model (saying the SVF) via uploading a ZIP file that contains the host model and links and passing both rootFilename and compressedUrn parameters to the POST job request payload.

curl -X POST \
  https://developer.api.autodesk.com/modelderivative/v2/designdata/job \
  -H 'Content-Type: application/json; charset=utf-8' \
  -H 'Authorization: Bearer {ACCESSTOKEN}'
  -H 'cache-control: no-cache' \
  -d '{
   "input": {
     "urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YXBwdGVzdGJ1Y2tldC9iYXNpY19zYW1wbGVfcHJvamVjdC56aXA",
     "compressedUrn": true,
     "rootFilename": "rac_basic_sample_project_linked.rvt"
   },
   "output": {
     "formats": [
       {
         "type": "svf",
         "views": [
           "2d",
           "3d"
         ]
       }
     ]
   }
 }'

But what If we want to achieve the same goal on BIM360 Docs, how can we do?  BIM360 Docs doesn't support ZIP file format translation currently.

 

Fortunately, there is a function called "Upload Linked Files" on the BIM360 Docs Web UI, and we do support a similar thing on the Forge API side. So, let's see how magic it is!

 

The following tutorial will use Revit models (rac_basic_sample_project.rvt & rst_basic_sample_project.rvt) as examples, and The rst_basic_sample_project.rvt is a external link inside the rac_basic_sample_project.rvt. (Note. rac_basic_sample_project.rvt is renamed as rac_basic_sample_project_linked.rvt inside this toturial.)

External link configs within Revit

Before getting started, there is something you need to know:

  • The RVT files of Revit external links have to be uploaded first before creating link info. (xrefs) on the host RVT file (i.e. parent file) in order to obtain version ids of those external links, e.g. urn:adsk.wipprod:fs.file:vf.b909RzMKR4mhc3O7UBY_8g?version=2
  • Revit links within the host RVT file must be set up before uploading it to the BIM360 OSS Bucket (WIPDM). It's a known limitation of the Forge Revit extractor.
  • The storage spaces created by POST projects/:project_id/storage could be used once only after uploading a file onto it. After then, you cannot upload new files to this storage space anymore.

Ok, here are the magic steps for the new host RVT model:

  1. Obtain version ids of the external link files via calling GET Folder Contents or GET items/:item_id.
  2. Create a storage location and upload the host model as usual (toturial link).
  3. Create the first version with the xrefs configurations via calling POST projects/:project_id/items with this request body (payload):
{
   "jsonapi":{
      "version":"1.0"
   },
   "data":{
      "type":"items",
      "attributes":{
         "displayName":"{{Filename}}",
         "extension":{
            "type":"items:autodesk.bim360:File",
            "version":"1.0"
         }
      },
      "relationships":{
         "tip":{
            "data":{
               "type":"versions",
               "id":"1"
            }
         },
         "parent":{
            "data":{
               "type":"folders",
               "id":"{{FolderId}}"
            }
         }
      }
   },
   "included":[
      {
         "type":"versions",
         "id":"1",
         "attributes":{
            "name":"{{Filename}}",
            "extension":{
               "type":"versions:autodesk.bim360:File",
               "version":"1.0"
            }
         },
         "relationships":{
            "storage":{
               "data":{
                  "type":"objects",
                  "id":"{{URN}}"
               }
            },
            "refs": {   //!<<< The key to set up model links
                "data": [{
                        "type": "versions",
                        "id": "{{VersionURNforLink1}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink2}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink3}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    },
                    // ... other links
                ]
            }
         }
      }
   ]
}

Example of the first version request payload:

{
   "jsonapi":{
      "version":"1.0"
   },
   "data":{
      "type":"items",
      "attributes":{
         "displayName":"rac_basic_sample_project_linked.rvt",
         "extension":{
            "type":"items:autodesk.bim360:File",
            "version":"1.0"
         }
      },
      "relationships":{
         "tip":{
            "data":{
               "type":"versions",
               "id":"1"
            }
         },
         "parent":{
            "data":{
               "type":"folders",
               "id":"urn:adsk.wipprod:fs.folder:co.AijQHeiLT7mqLc1Eow-Geg"
            }
         }
      }
   },
   "included":[
      {
         "type":"versions",
         "id":"1",
         "attributes":{
            "name":"rac_basic_sample_project_linked.rvt",
            "extension":{
               "type":"versions:autodesk.bim360:File",
               "version":"1.0"
            }
         },
         "relationships":{
            "storage":{
               "data":{
                  "type":"objects",
                  "id":"urn:adsk.objects:os.object:wip.dm.prod/8447edd0-a468-41ee-b47b-3e7214944b10.rvt"
               }
            },
            "refs": {
                "data": [{
                        "type": "versions",
                        "id": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }
                ]
            }
         }
      }
   ]
}

Afterward, you will see structural elements of the rst_basic_sample_project.rvt appear within the rac_basic_sample_project_linked.rvt on the Docs.

Final result after setting xrefs

 

In addistion, you may ask how about setting xrefs up for host model and reman its file revision history. Sure, it's quite simple and strightforward by appeding a new tip version. The first two steps are similar to the first-version one:

  1. Obtain version ids of the file that are going to be linked.
  2. [IMPORTANT] Creat new storage space for the host model and upload the RVT file onto it again.
  3. Create a new tip version for configuaring xrefs with calling POST projects/:project_id/versions with this request body (payload):
{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "versions",
        "attributes": {
            "name": "{{Filename}}",
            "extension": {
                "type": "versions:autodesk.bim360:File",
                "version": "1.0"
            }
        },
        "relationships": {
            "item": {
                "data": {
                    "type": "items",
                    "id": "{{ItemId}}"
                }
            },
            "storage": {
                "data": {
                    "type": "objects",
                    "id": "{{URN}}"
                }
            },
            "refs": {   //!<<< The key to set up model links
                "data": [{
                        "type": "versions",
                        "id": "{{VersionURNforLink1}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink2}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink2}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    },
                    // ... other links
                ]
            }
        }
    }
}

Example request payload for creating a tip version:

{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "versions",
        "attributes": {
            "name": "rac_basic_sample_project_linked.rvt",
            "extension": {
                "type": "versions:autodesk.bim360:File",
                "version": "1.0"
            }
        },
        "relationships": {
            "item": {
                "data": {
                    "type": "items",
                    "id": "urn:adsk.wipprod:dm.lineage:y3L7YbfAQJWwumMgqjJUxg"
                }
            },
            "storage": {
                "data": {
                    "type": "objects",
                    "id": "urn:adsk.objects:os.object:wip.dm.prod/8447edd0-a468-41ee-b47b-3e7214944b10.rvt"
                }
            },
            "refs": {
                "data": [{
                        "type": "versions",
                        "id": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
}

So, the final result! Now we use the BIM360 version comprasion tool to see the content changes. All structural contents are shown in the acrchitecture model.

Final result of xrefs configs by appending new file version

 

UPDATE 2019 Nov. 21th:

New way to configure xrefs for an existing host model and reman its file revision history. There is a new query string parameter of the POST projects/:project_id/versions called copyFrom. With this parameter, we can ignore the file uploading processes mentioned above, make our life more easier. So, the API call will become shorter:

// POST https://developer.api.autodesk.com/data/v1/projects/{PROJECT_ID}}/versions?copyFrom={{ESCAPED_VERSION_ID}}
{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "versions",
        "relationships": {
            "refs": {   //!<<< The key to set up model links
                "data": [{
                        "type": "versions",
                        "id": "{{VersionURNforLink1}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink2}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }, {
                        "type": "versions",
                        "id": "{{VersionURNforLink2}}",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    },
                    // ... other links
                ]
            }
        }
    }
}

Example request payload for the new method:

// POST https://developer.api.autodesk.com/data/v1/projects/{PROJECT_ID}}/versions?copyFrom=rn%3Aadsk.wipprod%3Afs.file%3Avf._AMHUWsSS-S8PHQBILp3lQ%3Fversion%3D1
{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "versions",
        "relationships": {
            "refs": {
                "data": [{
                        "type": "versions",
                        "id": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
                        "meta": {
                            "refType": "xrefs",
                            "direction": "from",
                            "extension": {
                                "type": "xrefs:autodesk.core:Xref",
                                "version": "1.1",
                                "data": {
                                    "nestedType": "overlay"
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
}

 

Posted by

Eason Kang is a member of the Autodesk Developer Network ADN DevTech team, focusing on providing programming support, consulting, training and evangelism to external developers. He started his career Taiwan and now lives in Taipei, Taiwan.


He is a developer consultant in the team DevTech, the worldwide team of API gurus providing technical services through the Autodesk Developer Network. He supports various products APIs...

Related Posts