27 Nov 2022

New sample to support access Revit Cloud Model from Revit Design Automation Engine

Default blog image

We announced Design Automation API supports Revit Cloud Model directly weeks ago, and I enhanced one of my sample to support access Revit Cloud Model directly, here I want to share some key point when you are accessing RCW(Revit Cloud Worksharing model) instead of a normal Revit model.

  • The original sample is at https://github.com/Autodesk-Forge/design.automation-nodejs-revit.parameters.excel .
  • The new enhanced sample is at https://github.com/Autodesk-Forge/design.automation-nodejs-revit.rcw.parameters.excel

The workflow of 2 samples works almost exactly same, and here are a couple of things you need to pay attention while accessing RCW model directly:

To access the file-based Revit models as input or output, developers usually provide the link of the storage in the workitem, and then Revit Design Automation will download the input file from the storage link to the engine, or upload the generated/modified result to the output file storage from engine. You can refer the details at https://github.com/Autodesk-Forge/design.automation-nodejs-revit.parameters.excel/blob/master/routes/common/da4revitImp.js#L146. Please noted that the sample uses the latest new feature to support direct S3 access from Design Automation, please check my previous blog for the details.

While accessing Revit Cloud Model, there is no need to download the input models, or generate the new result models, so developers don't need to provide the model storage link, instead, just need to provide the cloud information of the RCW model, including Region, ProjectGuid, ModelGuid, which developers can get by the GET Version API, if the file is type of "versions:autodesk.bim360:C4RModel", they can get the info by response.data.attributes.extension.data.projectGuid and response.data.attributes.extension.data.modelGuid. Refer the details at https://github.com/Autodesk-Forge/design.automation-nodejs-revit.rcw.parameters.excel/blob/main/routes/common/datamanagementImp.js#L187.

When developers get the cloud information of the Revit Cloud Model, they can easily pass the information as a JSON input file, and instead of opening/modifying the downloaded Revit model in the plugin, developers just need to use the following API to operate the Revit Cloud Model directly with cloud path:

  • Open the Cloud Model: 
        var cloudModelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(inputParams.Region, inputParams.ProjectGuid, inputParams.ModelGuid);
        Document doc = rvtApp.OpenDocumentFile(cloudModelPath, new OpenOptions());
  • Synchronize Revit Cloud Worksharing Model with central(need to publish later):
         if (doc.IsWorkshared) // work-shared/C4R model
         {
            SynchronizeWithCentralOptions swc = new SynchronizeWithCentralOptions();
            swc.SetRelinquishOptions(new RelinquishOptions(true));
            doc.SynchronizeWithCentral(new TransactWithCentralOptions(), swc);
         }
  • Create a new Revit Cloud Model:
         Document newDoc = data.RevitApp.NewProjectDocument(UnitSystem.Imperial);
         this.AddWalls(newDoc);
         var cloudModelLocation = CloudModelLocation.Parse("CloudModelLocation.json");
         newDoc.EnableWorksharing("Shared Levels and Grids", "Workset1");
         newDoc.SaveAsCloudModel(cloudModelLocation.AccountId, cloudModelLocation.ProjectId, cloudModelLocation.FolderId, "newRCWModel.rvt");

Be noted that after developers synchronize the change with central, if the model needs to be published, developers can use Data Management API Publish Model Command to publish to cloud within the onComplect() callback. Please check the workflow, and also refer the code here.

The last but not least change is about the access permission, in order to access cloud models within Revit Design Automation engine, developers need to provide the user context through a special workitem argument adsk3LeggedToken as follow, which requires scope=code:all, if the adsk3LeggedToken workitem argument is not included or incorrect, the Revit Cloud Model APIs such as Document.OpenDocumentFile() will not be able to open a cloud model. Refer the sample code for details.

        {
            inputXls: {
                url: "XXXXXXXXXX"
            },
            onComplete: {
                verb: "post",
                    url: designAutomation.webhook_url
            },
            adsk3LeggedToken: access_token
        }

Hope if helps, and enjoy your journey with APS:)

Related Article