Revit incompatible with Autodesk SDKs?

Revit incompatible with Autodesk SDKs?

kaiZQHQ4
Participant Participant
146 Views
5 Replies
Message 1 of 6

Revit incompatible with Autodesk SDKs?

kaiZQHQ4
Participant
Participant

So I'm trying to integrate some APS functionality into my Revit addins, namely so I can use Parameters Service. However, It seems like the newest versions of Autodesk.Authentication and Autodesk.DataManagement are incompatible with Revit 25 and 26 (and completely incompatible with 23/24). Am I missing something, it doesn't make sense to me that the SDKs exist but I can't use them?! I can downgrade the Authentication package to 1.0.0 and it works, but DataManagment doesn't work at all.

The error that I get is this:

```

Could not load file or assembly 'System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)

```

 

Part of the root of the issue is that i'm using System.Text.Json in my code but for quite a few reasons I dont want to stop. I really do feel like i'm missing something because it seems inconceivable to me that your expected not to use the System.Text.Json library in a Revit addin. 

This is my Repo: https://github.com/kaitpw/PE_Tools
The error that i pasted happens as soon as I enter the Json.cs file (if the Autodesk.Authentication package is v2+)

Accepted solutions (1)
147 Views
5 Replies
Replies (5)
Message 2 of 6

ricaun
Advisor
Advisor
Accepted solution

The APS Autodesk SDK was not design to work inside Revit or other Autodesk desktop products. 

 

The .Net Standard 2.0 was dropped and make the libraries unsupported for NET Framework like Revit 2024-.

 

I believe the APS Autodesk SDK is design to work with ASP.NET in the web.

 

For desktop should work fine in a standalone application, but inside Revit you gonna have issues with dependency conflict like your error or this problem:

 

The Parameters Service is not integrated in the main Revit API in the ParameterUtils?

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 3 of 6

kaiZQHQ4
Participant
Participant

Ignore this reply, can't figure out how to delete it

0 Likes
Message 4 of 6

kaiZQHQ4
Participant
Participant

This is very disappointing to hear but I guess not the end of the world, thanks for the suggestion about standalone app. I think I may do that or a something similar in Typescript instead. At the end of the day i feel like making web requests from the Revit thread is kinda a bad idea anyways

 

I am a little confused by this comment though, I can't tell if I'm misreading it or if there's a typo:

"""

The Parameters Service is not integrated in the main Revit API in the ParameterUtils?

"""

To me this does look like its integrated (?). I was planning on using this at least, I haven't tested it but i found an example of its use on github: revit-parameters-export-addin.

 

Edit:

Did you mean that it's not directly integrated into the Revit API? I've successfully written some methods to fetch the parameter data from Parameters Service (Http client is passed down from a wrapper class):

 

using PeServices.Aps.Models;
using System.Net.Http;
using System.Text.Json;

namespace PeServices.Aps.Core;

public class Parameters(HttpClient httpClient) {
    private const string Suffix = "parameters/v1/accounts/";

    private static async Task<T> DeserializeToType<T>(HttpResponseMessage res) =>
        JsonSerializer.Deserialize<T>(
            await res.Content.ReadAsStringAsync(),
            new JsonSerializerOptions { PropertyNameCaseInsensitive = true }
        );

    private static string Clean(string v) => v.Replace("b.", "").Replace("-", "");

    public async Task<ParametersApi.Groups> GetGroups(string hubId) {
        var response = await httpClient.GetAsync(Suffix + Clean(hubId) + "/groups");
        return response.IsSuccessStatusCode
            ? await DeserializeToType<ParametersApi.Groups>(response)
            : new ParametersApi.Groups();
    }

    public async Task<ParametersApi.Collections> GetCollections(string hubId, string grpId) {
        var response = await httpClient.GetAsync(
            Suffix + Clean(hubId) + "/groups/" + Clean(grpId) + "/collections?offset=0&limit=10"
        );
        return response.IsSuccessStatusCode
            ? await DeserializeToType<ParametersApi.Collections>(response)
            : new ParametersApi.Collections();
    }

    public async Task<ParametersApi.Parameters> GetParameters(string hubId, string grpId, string colId) {
        var response = await httpClient.GetAsync(
            Suffix + Clean(hubId) + "/groups/" + Clean(grpId) + "/collections/" + Clean(colId) + "/parameters"
        );
        return response.IsSuccessStatusCode
            ? await DeserializeToType<ParametersApi.Parameters>(response)
            : new ParametersApi.Parameters();
    }
}

 

 

0 Likes
Message 5 of 6

ricaun
Advisor
Advisor

@kaiZQHQ4 wrote:

I am a little confused by this comment though, I can't tell if I'm misreading it or if there's a typo:


I mean ParameterUtils have some methods to download shared parameters from the Parameters Service. I guess you want other stuff.

 


@kaiZQHQ4 wrote:

This is very disappointing to hear but I guess not the end of the world, thanks for the suggestion about standalone app. I think I may do that or a something similar in Typescript instead. At the end of the day i feel like making web requests from the Revit thread is kinda a bad idea anyways

 


 

Usually is easier to recreate your HttpClient implementation for the Parameters Service API inside Revit, you can run async methods inside the main Revit thread but need to be careful.

 

In genera you can force any Task method to wait using task.GetAwaiter().GetResult(), 

 

Here is a full sample.

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Threading.Tasks;

namespace RevitAddin
{
    [Transaction(TransactionMode.Manual)]
    public class CommandTodos : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
        {
            UIApplication uiapp = commandData.Application;

            var task = Task.Run(async () =>
            {
                using (var httpClient = new System.Net.Http.HttpClient())
                {
                    var response = await httpClient.GetAsync("https://jsonplaceholder.typicode.com/todos/1");
                    return await response.Content.ReadAsStringAsync();
                }
            });
            var content = task.GetAwaiter().GetResult();
            TaskDialog.Show("todos", content);

            return Result.Succeeded;
        }
    }
}

 

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 6 of 6

ricaun
Advisor
Advisor

@kaiZQHQ4 wrote:

I've successfully written some methods to fetch the parameter data from Parameters Service (Http client is passed down from a wrapper class):

 

Nice! I probably would change the System.Text.Json to Newtonsoft.Json, to prevent dependency problems.

 

Revit already ship Newtonsoft.Json in basically all Revit version, so you don't need to ship the dll.

 

I usually use this in my RevitAddin code to have the Newtonsoft.Json reference.

    <PackageReference Include="Newtonsoft.Json" Version="9.*" IncludeAssets="build; compile" PrivateAssets="All">
      <NoWarn>NU1903</NoWarn>
    </PackageReference>

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes