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