如何使用Design Automation发布新版本文件BIM 360云模型?

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

当我尝试将新参数覆盖更新到 BIM 360 云 Revit 模型并发布 Revit 模型的新发布版本时遇到问题,

示例:BIM 360 中文件名为

sample.rvt
的最新版本模型是版本
1
。设置参数后将成为文件名
sample.rvt
,版本为
2

这些是我试图实现的步骤:

  • 创建捆绑应用程序更新参数
    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);
    }
    
  • 创建活动
    Activity activitySpec = new Activity()
    {
       // Activities 
       ... 
    }
    
  • 执行工作项目
    private async Task<Status> ExecuteWorkItem(string forgeToken,List<InputParams> inputParams, string projectId, string versionId, string callBackUrl)
        ...
    
  • 发布新版本 - 我不知道如何实现这个

我在最后一步(发布新版本)失败了,因为我在 GitHub 上找不到任何用于从刚刚保存为文件到存储桶的 BIM360 模型发布新版本的示例。如果您有任何 C# 代码示例,如果您分享它,我将不胜感激。

c# autodesk-forge autodesk-designautomation
1个回答
-1
投票

检查此代码。

private void PostNewVersion(string forgeToken, string projectId, string itemId, string newVersion, string callbackUrl)
{
    RestClient client = new RestClient("https://developer.api.autodesk.com/data/v1/projects/" + projectId + "/versions");
    RestRequest request = new RestRequest(Method.POST);
    request.AddHeader("Authorization", "Bearer " + forgeToken);
    request.AddHeader("Content-Type", "application/json");
    
    // Prepare the request body with version details
    string requestBody = $"{{\"data\": {{\"type\": \"versions\",\"attributes\": {{\"name\": \"YourModelName\",\"extension\": {{\"type\": \"versions:autodesk.bim360:File\",\"version\": \"{newVersion}\"}}}},\"relationships\": {{\"item\": {{\"data\": {{\"type\": \"items\",\"id\": \"{itemId}\"}}}}}}}},\"jsonapi\": {{\"version\": \"1.0\"}}}}";
    request.AddParameter("application/json", requestBody, ParameterType.RequestBody);

    // Execute the request
    IRestResponse response = client.Execute(request);
    
    // Handle the response
    if (response.StatusCode == HttpStatusCode.Created)
    {
        // Version created successfully
        string versionId = response.Headers
            .FirstOrDefault(h => h.Name == "Location" && h.Value.ToString().Contains("versions"))
            ?.Value?.ToString();
        
        // Now, you can associate the storage location with the new version (not shown in this example)
        UpdateStorageLocation(forgeToken, projectId, versionId, callbackUrl);
    }
    else
    {
        // Handle error
        Console.WriteLine("Error creating version: " + response.Content);
    }
}

private void UpdateStorageLocation(string forgeToken, string projectId, string versionId, string callbackUrl)
{
    // Implement the logic to update storage location
    // Use the projects/:project_id/storage endpoint to associate the model with the new version
    // Refer to Forge Data Management API documentation for details
}
© www.soinside.com 2019 - 2024. All rights reserved.