Hi guys,
I am currently writing a Rhino plug in and wanted to embed some simple Speckle functionality directly from it. As the first step i am trying to receive a Speckle stream:
public static async Task Main()
{
var account = new Account();
account.token = “my-access-token”;
account.serverInfo = new ServerInfo
{
url = “https://app.speckle.systems/”
};var streamId = "my-stream-id"; var branchName = "my-branch-name"; var client = new Client(account); var branch = await client.BranchGet(streamId, branchName, 1); var objectId = branch.commits.items[0].referencedObject; // take last commit var transport = new ServerTransport(account, streamId); Base data = await Operations.Receive( objectId, remoteTransport: transport, localTransport: transport ); return data;
}
public static object Converter(Base data, RhinoDoc doc)
{
var kits = KitManager.Kits;
ISpeckleKit kit = KitManager.GetDefaultKit();
ISpeckleConverter converter = kit.LoadConverter(HostApplications.Rhino.GetVersion(HostAppVersion.v8));
converter.SetContextDocument(doc);
object result = converter.ConvertToNative(data);return result;
}
And then it is wrapped in default Rhino RunCommand method inside of the C# Rhino Plug-in template :
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Base speckleCall = SpeckleConnector.Connector.Main().Result; object native = Connector.Converter(speckleCall, doc); RhinoApp.WriteLine(native.ToString()); return Result.Success; }
The data receiving seems to be alright. I get a valid JSON response:
{
“name”: “Rhino Model”,
“collectionType”: “rhino model”,
“elements”: [ … ],
“totalChildrenCount”: 0,
“applicationId”: null,
“speckle_type”: “Speckle.Core.Models.Collection”,
“id”: “fa903099d066259e8fb6e9bef8e2aca7”
}
The problems start during the conversion of the Base object to the Rhino Native. In my understanding the converter interprets the initial “Rhino model” collection as a rhino layer and attempts to get the collection’s ‘path’ property which results in a null value. Here is the breakpoint (ConverterRhinoGh.cs file):
public ApplicationObject CollectionToNative(Collection collection)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
ApplicationObject val = new ApplicationObject(((Base)collection).id, ((Base)collection).speckle_type)
{
applicationId = ((Base)collection).applicationId
};
string text = MakeValidPath(((DynamicBase)collection)[“path”] as string);
Layer layer = GetLayer(text);
Layer layer2;
State value;
if (layer != null && (int)ReceiveMode == 0)
{
layer2 = layer;
value = (State)3;
}
else
{
Layer layer3 = null;
int num = text.LastIndexOf(Layer.PathSeparator); // Here i get the NullReferenceException error
I’ve been stuck with it for quite a while, so i would appreciate your suggestions.
best,
Konstantin