19 Sep 2019

Upload your Design Automation output file to BIM360 Docs

Default blog image

Follow @JohnOnSoftware

Sometimes, Design Automation service will work together with other Forge services, and use Data Management Service to access the file from BIM360 Docs as input or output is a typical workflow. Today we are going to talk about how to access the file from BIM360 Docs as input & output, we will be based on the Revit Parameters Update sample, the sample basically can export parameters to excel from Revit file version on BIM360 Docs, and also can update the Revit model in BIM360 with a new version by importing the modified excel file. It uses BIM360 Docs files as both input and output.  

First, let’s say, I want to use a Revit model from BIM360 as input file for my Design Automation Activity, usually, I can get the storage of the file version following the way mentioned at tutorials, can we just sign the Url with the endpoint POST https://developer.api.autodesk.com/oss/v2/buckets/:bucketKey/objects/:objectKey/signed? Unfortunately the answer is No, the reason is that you have to be the owner of the bucket(wip.dm.prod) to sign the Url, but most of the case, you are not the owner of that bucket. 

So, to provide the access to Design Automation engine for your BIM360 file version, the way we suggested is to use the file version storage Url together with your access token, check code for the details, to make it simple, use PostMan as example, the input argument of your workitem should be something like:

{
    "activityId":"{{dasNickName}}.CreateWindowFamilyActivity+dev",
    "arguments":{
        "templateFile":{
            "url":"https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.rvt",
                      "Headers":{
                        "Authorization":"Bearer {{3LeggedAccessToken}}"
                    }
        }
    }
}  

Now, let’s talk about how to upload the generated output file from Design Automation engine to BIM360 Docs, this is a little more complicated than input. The 1st step is to prepare a storage for the new version of the file, if you are not familiar with that, please follow the tutorial until the step 6 to get the file storage Url, then same as above, you need to provide the storage Url together with your access token for the output argument, something as follow using PostMan:

{
    "activityId":"{{dasNickName}}.CreateWindowFamilyActivity+dev",
    "arguments":{
        "templateFile":{
            "url":"https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.rvt",
                      "Headers":{
                        "Authorization":"Bearer {{3leggedAccessToken}}"
                    }
        },       
        "outputFamily":{
            "verb":"put",
            "url":" https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/2a6d61f2-49df-4d7b.rvt",
            "Headers":{
                        "Authorization":"Bearer {{3leggedAccessToken}}"
            }
        }
    }
}

Until now, the Design Automation engine can upload the generated output file directly to the BIM360 storage as we provided, but we are still not done yet. For BIM360, to make the file visible to user, we need to either create a first file version or new version of the file as you can see from the tutorial above. How can we do that? We need to use the special output argument named ‘onComplete’  which can be referenced at design automation tutorial , this is the callback Url which will be called on completion of the workitem. Thanks to this callback, we can create first file version or add a new file version within this callback. You can check the code for what I did for this sample.

Now, you should be able to upload your generated output file from Design Automation engine to BIM360 Docs and view it in UI. But still, here is a couple of things which might be important for you to be aware:

  1. About access token, we know Design Automation service support 2 legged access token, but to access the file in BIM360 Docs, we would suggest to use 3 legged access token.  
  2. To handle your BIM360 file version within the “onComplete” callback, you need to provide more information, here I created a workitem list to keep the relationship for workitem id, 3 legged access token, bim360 project id and create version body, they should be used in the onComplete callback, please check my code. For this sample, it uses simple way just for demo purpose, but I would suggest to use the database to keep these information if you are creating a real project.

Good luck coding with Design Automation service ?

Related Article