Can't add reference dll for pyrevit hooks scripts

Hi,
I am trying to use hooks to POST some basic model data to an HTTP address, but the script is not working with pyRevit. I tested the code it’s working fine when I change it to a standard Revit add-in. I assume may because we are not able to add reference dll for the hooks script(dll for HTTP and JSON?).
Is there anyone can advise on this?
Thanks in advance.

Reference Code here:

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Windows.Forms;

namespace pyRevitExtension.hooks
{
public class doc_opening
{
public static readonly HttpClient client = new HttpClient();

    public static readonly Uri uri =
        new Uri(
            ""
            );

    public void MyEventMgr_UiApp_DocOpened(object sender, DocumentOpenedEventArgs e)
    {
        var rvtData = GetModelInfor(e.Document);

        var buffer = JsonSerializer.SerializeToUtf8Bytes(rvtData);
        var byteContent = new ByteArrayContent(buffer);

        byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var result = client.PostAsync(uri, byteContent).Result;
        //MessageBox.Show(result.ReasonPhrase);
    }
    private static ModelInfor GetModelInfor(Document doc)
    {

        var modelInfor = new ModelInfor()
        {
            ModelTitle = doc.Title,
        };

        if (doc.IsModelInCloud)
        {
            try
            {
                var modelPath = doc.GetCloudModelPath();
                modelInfor.ModelGuid = modelPath.GetModelGUID().ToString();
                modelInfor.ProjectGuid = modelPath.GetProjectGUID().ToString();
            }
            catch (Exception e)
            {
            }
        }
        else
        {
            modelInfor.ModelGuid = "-";
            modelInfor.ProjectGuid = "-";
        }

        return modelInfor;

    }
    class ModelInfor
    {
        public string ModelTitle { get; set; }
        public string ModelGuid { get; set; }
        public string ProjectGuid { get; set; }
    }
}

}

If it works fine in a C# addin, why trying the same in pyRevit?
I did use pyRevit in python to post stuff to an api with no issue importing the json module → because it is part of the pyRevit Framework.
Maybe try something simple without the modules imports (json, http, etc.) first.

Why the double post? not able to add external dll reference for hooks event script · Issue #1686 · eirannejad/pyRevit · GitHub
Can you close the issue at least?

Hi Jean,

Coz we have quite a big team here, we want to use pyRevit to distribute our adding function and we place our extension file to an shared folder, and pyRevit can load the script from the shared folder automatically for user.
For the reference dll I see it’s working well for the normal bundle we just put it to the bin folder, but for hooks script we don’t have bin folder there. just wondering if there any way just same like what we did for normally bundle to provide reference dll to hooks script.

Regarding this github issue #1686 I raised, just because some people they are not using pyRevit forum so that I have posted in these two channel both.

And for your suggestion I do tried to simplify the scrip but still not working, I removed JSON part only keep HTTP there.

Thanks

I am guessing you could refer explicitly to the dll location from your hook script?

Hi Jean,
As I understand the pyRevit correctly. we have .bin forlder for reference dll that can only under panel folder and it’s working for the script under this panel folder. but hooks folder is high level folder that is not working with panel level .bin folder.
image

Hi issue resolved, I have used reflection to instead using dll directly.

1 Like

Cool,
I guess you now have to close the issue on GitHub :grinning:

1 Like