speckle-sharp icon indicating copy to clipboard operation
speckle-sharp copied to clipboard

Rhino Converter returns null if ReceiveMode is Ignore or Create

Open Sticcia opened this issue 1 year ago • 3 comments

Prerequisites

What package are you referring to?

Converters/ConverterRhinoGh

Describe the bug

We are setting up a Rhino Converter as follows:

Converter = new ConverterRhinoGh();
Converter.SetConverterSettings(MeshSettings.CurrentDoc);
Converter.SetContextDocument(doc);

Then using it to convert a a BlockInstance with Converter.ConvertToNative(). This works fine if we leave the ReceiveMode to the default value Update but we if we change it to Create or Ignore, Converter.ConvertToNative() returns null when converting the same object twice. Added the following to the converter setup block above:

Converter.ReceiveMode = ReceiveMode.Create;
Converter.SetConverterSettings(ReceiveMode.Create);

With this configuration, Converter.ConvertToNative() returns the expected result on the first execution but null on all the following runs. We need to convert the same object multiple times, with ReceiveMode.Update the object is replaced instead of creating a new object. I tried replacing the id and applicationId on the BlockInstance, is there something else that needs to be done before calling Converter.ConvertToNative()?

To Reproduce

  1. Setup a Converter with Converter.ReceiveMode = ReceiveMode.Create;
  2. Call Converter.ConvertToNative() on a BlockInstance (successful)
  3. Call Converter.ConvertToNative() on the same BlockInstance (returns null)

Expected behavior

Converter.ConvertToNative() always returns the converted BlockInstance adding a new block to the Document every time.

System Info

  • Grasshopper: 7.32.23221.10241
  • Speckle.Core: 2.15.3
  • Speckle.Objects: 2.15.3

Failure Logs

No logs, also Converter.Report has no errors.

Proposed Solution

  • Add documentation and examples on how to change the converter receive mode

Sticcia avatar Oct 09 '23 08:10 Sticcia

Hi @Sticcia!

Thanks for reporting this. It seems the converter is failing to create the same block definition over again, which causes the conversion to return null. On Update the converter will remove the block with the same name before adding the new one, but for create the behaviour is it will just fail.

You may be seeing a message like this on the Rhino command window Screenshot 2023-10-10 at 11 58 45

Your use-case seems valid, and I'll admit it's not ideal to have things fail with no developer feedback so I'll talk to the team and try to come up with a way forward that is more intuitive and hopefully better documented! 🙌🏼

AlanRynne avatar Oct 10 '23 10:10 AlanRynne

Hi @AlanRynne,

Thanks for the quick support. As I understand from your message you will add some form of logging of the error. But how would we avoid hitting the error altogether? Should we rename the BlockInstance or the Definition? Would assigning a new ID be enough?

Sticcia avatar Oct 10 '23 13:10 Sticcia

Renaming the definition to something else would do. Block definitions are matched by name from the RhinoDoc.ActiveDoc.InstanceDefinitions property, so you could try checking for that.

Ideally, this is something we should both fix so that create mode works and also clarify what should be the expectation for it.

AlanRynne avatar Oct 10 '23 13:10 AlanRynne