如何使用设计自动化更新 Revit 模型 BIM360 Cloud CompositeDesign 参数?

问题描述 投票:0回答:1

我有问题需要更新

Architect
模型(.rvt)使用
Composite Design
与BIM360上的许多模型链接。但是当我尝试使用设计自动化时,我在最新一步失败了。让我一步步展示我试图实现的目标:

  1. 解压缩复合设计自动化(已工作)
  2. 通过参数名称为元素设置新值(已工作)
  3. 更新
    Composite Design
    模型(.rvt)的新版本 - 我不知道如何使用Zip文件更新版本?.

可以给我一个例子来完成第3步,我只用单个文件(.rvt)成功,这是我的代码:

private static async Task<string> CreateFileStorage(string projectId, string folderUrn, string filename,
        string accessToken)
    {
        ProjectsApi projectsApi = new ProjectsApi();
        projectsApi.Configuration.AccessToken = accessToken;

        var storageRelData =
            new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderUrn);
        var storageTarget = new CreateStorageDataRelationshipsTarget(storageRelData);
        var storageRel = new CreateStorageDataRelationships(storageTarget);
        var attributes =
            new BaseAttributesExtensionObject(string.Empty, string.Empty, new JsonApiLink(string.Empty), null);
        var storageAtt = new CreateStorageDataAttributes(filename, attributes);
        var storageData = new CreateStorageData(CreateStorageData.TypeEnum.Objects, storageAtt, storageRel);
        var storage = new CreateStorage(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), storageData);

        try
        {
            var res = await projectsApi.PostStorageAsync(projectId, storage).ConfigureAwait(false);
            string id = res.data.id;
            return id;
        }
        catch (ApiException ex)
        {
            throw new Exception(ex.Message);
        }
    }

    private static async Task<ObjectDetails> UploadFileAsync(string objectStorageId, MemoryStream fileMemoryStream,
        string accessToken)
    {
        var objectInfo = ExtractObjectInfo(objectStorageId);
        // Get object upload url via OSS Direct-S3 API
        var objectsApi = new ObjectsApi();
        objectsApi.Configuration.AccessToken = accessToken;

        var payload = new List<UploadItemDesc>
        {
            new UploadItemDesc(objectInfo.ObjectKey, fileMemoryStream)
        };

        var results = await objectsApi.uploadResources(
            objectInfo.BucketKey,
            payload
        ).ConfigureAwait(false);

        if (results[0].Error)
        {
            throw new Exception(results[0].completed.ToString());
        }

        var json = results[0].completed.ToJson();
        return json.ToObject<ObjectDetails>();
    }

    private static ObjectInfo ExtractObjectInfo(string objectId)
    {
        var result = System.Text.RegularExpressions.Regex.Match(objectId, ".*:.*:(.*)/(.*)");
        var bucketKey = result.Groups[1].Value;
        ;
        var objectKey = result.Groups[2].Value;

        return new ObjectInfo
        {
            BucketKey = bucketKey,
            ObjectKey = objectKey
        };
    }

    private static async Task<FileInfoInDocs> CreateFileItemOrAppendVersionAsync(string projectId, string folderUrn,
        string objectId, string filename, string accessToken)
    {
        ItemsApi itemsApi = new ItemsApi();
        itemsApi.Configuration.AccessToken = accessToken;
        string itemId = "";
        string versionId = "";
        // check if item exists
        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));
        FileInfoInDocs? fileInfo;
        if (item.Value != null)
        {
            //Get ItemId of our file
            itemId = item.Value.id;

            //Lets create a new version
            versionId = await UpdateVersionAsync(projectId, itemId, objectId, filename, accessToken).ConfigureAwait(false);

            fileInfo = new FileInfoInDocs
            {
                ProjectId = projectId,
                FolderUrn = folderUrn,
                ItemId = itemId,
                VersionId = versionId
            };

            return fileInfo;
        }
        var itemBody = new CreateItem
        (
            new JsonApiVersionJsonapi
            (
                JsonApiVersionJsonapi.VersionEnum._0
            ),
            new CreateItemData
            (
                CreateItemData.TypeEnum.Items,
                new CreateItemDataAttributes
                (
                    DisplayName: filename,
                    new BaseAttributesExtensionObject
                    (
                        Type: "items:autodesk.bim360:File",
                        Version: "1.0"
                    )
                ),
                new CreateItemDataRelationships
                (
                    new CreateItemDataRelationshipsTip
                    (
                        new CreateItemDataRelationshipsTipData
                        (
                            CreateItemDataRelationshipsTipData.TypeEnum.Versions,
                            CreateItemDataRelationshipsTipData.IdEnum._1
                        )
                    ),
                    new CreateStorageDataRelationshipsTarget
                    (
                        new StorageRelationshipsTargetData
                        (
                            StorageRelationshipsTargetData.TypeEnum.Folders,
                            Id: folderUrn
                        )
                    )
                )
            ),
            new List<CreateItemIncluded>
            {
                new CreateItemIncluded
                (
                    CreateItemIncluded.TypeEnum.Versions,
                    CreateItemIncluded.IdEnum._1,
                    new CreateStorageDataAttributes
                    (
                        filename,
                        new BaseAttributesExtensionObject
                        (
                            Type: "versions:autodesk.bim360:File",
                            Version: "1.0"
                        )
                    ),
                    new CreateItemRelationships(
                        new CreateItemRelationshipsStorage
                        (
                            new CreateItemRelationshipsStorageData
                            (
                                CreateItemRelationshipsStorageData.TypeEnum.Objects,
                                objectId
                            )
                        )
                    )
                )
            }
        );


        try
        {
            DynamicJsonResponse postItemJsonResponse = await itemsApi.PostItemAsync(projectId, itemBody).ConfigureAwait(false);
            var uploadItem = postItemJsonResponse.ToObject<ItemCreated>();
            Console.WriteLine("Attributes of uploaded BIM 360 file");
            Console.WriteLine($"\n\t{uploadItem.Data.Attributes.ToJson()}");
            itemId = uploadItem.Data.Id;
            versionId = uploadItem.Data.Relationships.Tip.Data.Id;
        }
        catch (ApiException ex)
        {
            //we met a conflict
            dynamic? errorContent = JsonConvert.DeserializeObject<JObject>(ex.ErrorContent);
            if (errorContent.Errors?[0].Status == "409") //Conflict
            {
                try
                {
                    //Get ItemId of our file
                    itemId = await GetItemIdAsync(projectId, folderUrn, filename, accessToken).ConfigureAwait(false);

                    //Lets create a new version
                    versionId = await UpdateVersionAsync(projectId, itemId, objectId, filename, accessToken).ConfigureAwait(false);
                }
                catch (Exception ex2)
                {
                    System.Diagnostics.Trace.WriteLine("Failed to append new file version", ex2.Message);
                }
            }
        }

        if (string.IsNullOrWhiteSpace(itemId) || string.IsNullOrWhiteSpace(versionId))
        {
            throw new InvalidOperationException("Failed to Create/Append file version");
        }

        fileInfo = new FileInfoInDocs
        {
            ProjectId = projectId,
            FolderUrn = folderUrn,
            ItemId = itemId,
            VersionId = versionId
        };

        return fileInfo;
    }

    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;
    }

    private static async Task<string> GetItemIdAsync(string projectId, string folderUrn, string filename,
        string accessToken)
    {
        FoldersApi foldersApi = new FoldersApi();
        foldersApi.Configuration.AccessToken = accessToken;
        DynamicDictionaryItems itemList = await GetFolderItems(projectId, folderUrn, accessToken).ConfigureAwait(false);
        var item = itemList.Cast<KeyValuePair<string, dynamic>>().FirstOrDefault(item =>
            item.Value.attributes.displayName.Equals(filename, StringComparison.OrdinalIgnoreCase));
        return item.Value?.Id;
    }

    private static async Task<DynamicDictionaryItems> GetFolderItems(string projectId, string folderId,
        string accessToken)
    {
        var foldersApi = new FoldersApi();
        foldersApi.Configuration.AccessToken = accessToken;
        dynamic folderContents = await foldersApi.GetFolderContentsAsync(projectId,
            folderId,
            filterType: new List<string>() {"items"},
            filterExtensionType: new List<string>() {"items:autodesk.bim360:File"}
        ).ConfigureAwait(false);

        var folderData = new DynamicDictionaryItems(folderContents.data);

        return folderData;
    }
}

public class ObjectInfo
{
    public string BucketKey { get; set; }
    public string ObjectKey { get; set; }
}

public class FileInfoInDocs
{
    public string ProjectId { get; set; }
    public string FolderUrn { get; set; }
    public string ItemId { get; set; }
    public string VersionId { get; set; }
}

如有任何帮助,我们将不胜感激!

autodesk-forge autodesk-designautomation
1个回答
0
投票

您可以看一下下面的链接吗?

https://aps.autodesk.com/blog/make-composite-revit-design-work-design-automation-api-revit

https://aps.autodesk.com/en/docs/data/v2/reference/http/PublishModel/

我正在从我的角度进行调查,并将尽快回复您并提供更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.