Failed Object Conversion on Rhino.Compute/Hops Environment

Hey guys,

I am having an issue while trying to use Hops/Rhino.Compute to receive data from Speckle.

The synchronous receiver works gracefully, and I am able to receive text, but something bad happens when I try to get geometry from my SpeckleObject.

Here is my sender.

And my hops/rhino.compute receiver.

Also, I have tried using the SpeckleToNative component inside the receiver definition and I get a similar error.

Any ideas of what might be causing it?

Oh, files:
receiver.gh (7.5 KB)
sender.gh (5.5 KB)

2 Likes

Hey @vwb welcome to our forum!

Does the receive operation work outside the Hops/Rhino.Compute context? If so, @Stam is the best one to help since he’s the author of the sync nodes!

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.

See this example:

And it works:

The exception happens when I attemp to get Rhino.Geometry from my SpeckleObject.

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… :boom: 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).

Does it make any sense?

conversion-test.gh (9.6 KB)