Hey Matteo, everything works as a charm outside the hops/compute context.
Doesn’t feel like the problem is with the sync nodes though. For example: inside the hops context, if I use a sync-receiver, get my message from the SpeckleObject and use a sync-sender to commit, it works.
Back at the trenches. I figured out the ToNative/ToSpeckle and some of the Speckle components are working asynchronously, which in my experience is hardly digested by Rhino.Compute.
So I went there to write my little C# components to make conversions.
private void RunScript(object B, ref object D, ref object tol)
{
// Grab kit and converter.
var kit = Speckle.Core.Kits.KitManager.GetDefaultKit();
var converter = kit.LoadConverter(Speckle.Core.Kits.Applications.Rhino);
// Provide context document to my converter.
var doc = RhinoDoc.CreateHeadless(null);
converter.SetContextDocument(doc);
if (converter.CanConvertToNative(B as Speckle.Core.Models.Base))
{
D = converter.ConvertToNative(B as Speckle.Core.Models.Base);
_converted = true;
}
}
bool _converted;
public override void AfterRunScript()
{
if (!_converted)
{
Component.Params.Output[0].ClearData();
}
}
So far so good. I was able to convert Points, Polylines, Meshes. But when I tried a Brep… Oops…
An exception occurred while processing request
System.NullReferenceException: Object reference not set to an instance of an object.
at Objects.Converter.RhinoGh.ConverterRhinoGh.BrepToNative(Brep brep)
at Objects.Converter.RhinoGh.ConverterRhinoGh.ConvertToNative(Base object)
at Script_Instance.RunScript(Object B, Object& D, Object& tol) in c:\Users\Victor\AppData\Local\Temp\z5oimfvg.0.cs:line 68
So I went on this method on the source and found this line:
public RH.Brep BrepToNative(Brep brep)
{
var tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
//...
RhinoDoc.ActiveDoc is null on the Rhino.Compute/Hops context. I was expecting the Converter to use the doc I passed on converter.SetContextDocument(doc).