Search code examples
c#autodesk-forgeautodesk-designautomation

How to post new version file BIM 360 cloud model using Design Automation?


I have a problem when I'm try to update new parameter override to BIM 360 cloud Revit model and post a new publish version for Revit model,

Example: The latest version model in BIM 360 with file name sample.rvt is version 1 . After set parameter will be become the file name sample.rvt with version 2.

These are the steps I'm tried to achieve :

  • Create bundle app update parameters
    private void DoJob(DesignAutomationData data)
    {
        if(data.RevitDoc == null) throw new Exception("Have problem with DesignAutomationData.RevitDoc");
        Document doc = data.RevitDoc;
        List<InputParams> inputParams = GetParamsJson();
        string result = SetParameterCommand.Execute(doc, inputParams);
        File.WriteAllText("result.txt", result);
    }
    
  • Create activity
    Activity activitySpec = new Activity()
    {
       // Activities 
       ... 
    }
    
  • Execute work item
    private async Task<Status> ExecuteWorkItem(string forgeToken,List<InputParams> inputParams, string projectId, string versionId, string callBackUrl)
        ...
    
  • Post new version - I don't know how to implement this

I failed with the last step, post new version, because I can't find any sample on GitHub for post new version from BIM360 Model just saved as file to bucket. If you have any C# code sample, I'd appreciate it if you shared it.


Solution

  • Finally I also have answer for my problem at this document: https://aps.autodesk.com/en/docs/bim360/v1/tutorials/document-management/upload-document-s3/

    This is step by step I resolved my problem :

    1. Create a new storage object

    2. Check file item exist and use this item if it exit.

      var items = await GetFolderItems(projectId, folderUrn, accessToken).ConfigureAwait(false);
            var item = items.Cast<KeyValuePair<string, dynamic>>().FirstOrDefault(item =>
                item.Value.attributes.displayName.Equals(filename, StringComparison.OrdinalIgnoreCase));
    
    1. Post a update version :
    • In case item not exitss, we create a new one .
    • In case item exites, keep use item id at previous version like urn:adsk.wipprod:dm.lineage:J-CiZHzFTGy-A0-RfhEUMQ:
     private static async Task<string> UpdateVersionAsync(string projectId, string itemId, string objectId,
            string filename, string accessToken)
        {
            var versionsApi = new VersionsApi();
            versionsApi.Configuration.AccessToken = accessToken;
    
            var relationships = new CreateVersionDataRelationships
            (
                new CreateVersionDataRelationshipsItem
                (
                    new CreateVersionDataRelationshipsItemData
                    (
                        CreateVersionDataRelationshipsItemData.TypeEnum.Items,
                        itemId
                    )
                ),
                new CreateItemRelationshipsStorage
                (
                    new CreateItemRelationshipsStorageData
                    (
                        CreateItemRelationshipsStorageData.TypeEnum.Objects,
                        objectId
                    )
                )
            );
            var createVersion = new CreateVersion
            (
                new JsonApiVersionJsonapi
                (
                    JsonApiVersionJsonapi.VersionEnum._0
                ),
                new CreateVersionData
                (
                    CreateVersionData.TypeEnum.Versions,
                    new CreateStorageDataAttributes
                    (
                        filename,
                        new BaseAttributesExtensionObject
                        (
                            "versions:autodesk.bim360:File",
                            "1.0",
                            new JsonApiLink(string.Empty),
                            null
                        )
                    ),
                    relationships
                )
            );
    
            dynamic versionResponse = await versionsApi.PostVersionAsync(projectId, createVersion).ConfigureAwait(false);
            var versionId = versionResponse.data.id;
            return versionId;
        }