如何在 C# 中使用 GetModelviewProperties API 获取大型模型属性

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

我正在尝试使用 C# 中的“GetModelviewProperties”API 获取大型模型属性。 (模型翻译为svf2格式)

我遇到了这个问题并收到了错误。

错误消息是

Autodesk.Forge.Client.ApiException: 'Error calling GetModelviewProperties: 
{"diagnostic":"Property Database is too large under this URN"}'

你有解决这个问题的想法吗?

c# autodesk-forge autodesk-model-derivative
2个回答
0
投票

正如文档所述,有一个

forceget
URL 查询参数可以设置为:

  • true
    :强制获取大量资源,即使它们超出了预期的最大大小(20 MB)。如果资源大于 800 MB,服务器的行为就好像forceget 为 false。在这种情况下,请使用 objectid 查询字符串参数按对象 ID 下载资源。
  • false
    :(默认)如果资源超过预期的最大大小 (20 MB),则不会获取资源。

另一种选择是使用其他格式之一而不是 JSON 来获取属性。请参阅此博客文章了解更多信息。


0
投票

当然!这是一个简洁的回应:

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

class Program
{
    static async Task Main()
    {
        try
        {
            string accessToken = "YOUR_ACCESS_TOKEN";
            string modelId = "YOUR_MODEL_ID";
            string apiEndpoint = "YOUR_ENDPOINT";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

                string apiURL = $"{apiEndpoint}/modelview/{modelId}/properties";
                HttpResponseMessage response = await client.GetAsync(apiURL);

                if (response.IsSuccessStatusCode)
                {
                    string responseBody = await response.Content.ReadAsStringAsync();
                    JArray propertiesArray = JObject.Parse(responseBody)["data"]["collection"].Value<JArray>();

                    foreach (JToken property in propertiesArray)
                    {
                        Console.WriteLine(property.ToString());
                    }
                }
                else
                {
                    Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}");
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Exception: {ex.Message}");
        }
    }
}

此版本保留了与以前的代码相同的功能,但形式更紧凑。在使用代码之前,请将占位符替换为您的实际凭据和端点。

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