Batch receive from speckle to revit

Hi all,

  • Objective: I’m trying to batch receive speckle data into Revit.
    As a test, I created some elemets in grasshopper as RevitFootprintRoof before sending them to multiple models within a single speckle project. I’m running grasshopper from within revit (Rhino.Inside.Revit) and using the C# node to receive the elements inside revit. For each model in my project, I’m create a revit document and add the geometries to those respective documents.

  • Issue: I’m unble to place the geometries inside revit, despite receiving them from speckle to grasshopper. To ensure that my roof elements are created properly, I used the revit speckle plugin to receive them and everything works as expected. Why am I unable to achieve the same from within grasshopper? Is this even possible? If not, what are the alternatives?

  • Example: Below, I provide the part of my code that receives speckle data from a single model and attempts to add it to revit.

private void RunScript(
    bool receive,
    object streamName,
    string modelName,
    ref object a)
{
    if (receive)
    {
        var t = Task<Base>.Run(async () =>
        {
            var sw = streamName as Speckle.Core.Credentials.StreamWrapper;
            var account = await sw.GetAccount();
            var client = new Client(account);

            var models = await client.Model.GetModels(sw.StreamId);
            var modelList = models.items;

            bool modelExists = modelList.Any(b => b.name.Equals(modelName, StringComparison.OrdinalIgnoreCase));

            if (modelExists)
            {
                var branch = await client.BranchGet(sw.StreamId, modelName, 1);
                var objectId = branch.commits.items[0].referencedObject;
                var transport = new ServerTransport(account, sw.StreamId);

                var receivedData = await Operations.Receive(objectId, remoteTransport: transport);
                return receivedData;
            }
            return null;
        });

        var myData = t.Result;
        if (myData == null)
        {
            Rhino.RhinoApp.WriteLine("Received data is null.");
            return;
        }

        var footprintsObj = myData["footprints"] as List<object>;
        if (footprintsObj == null)
        {
            Rhino.RhinoApp.WriteLine("No footprints found in received data.");
            return;
        }

        var footprints = footprintsObj.OfType<RevitFootprintRoof>().ToList();
        Rhino.RhinoApp.WriteLine($"Footprints to convert: {footprints.Count}");

        var doc = RhinoInside.Revit.Revit.ActiveDBDocument;
        var converter = new ConverterRevit();
        converter.SetContextDocument(doc);

        int countConverted = 0;
        using (var j = new DB.Transaction(doc, "Speckle Bake Footprints"))
        {
            try
            {
                j.Start();
                foreach (var roof in footprints)
                {
                    if (!converter.CanConvertToNative(roof))
                    {
                        Rhino.RhinoApp.WriteLine($"Cannot convert object: {roof.GetType()}");
                        continue;
                    }

                    var nativeObj = converter.ConvertToNative(roof);
                    if (nativeObj != null) countConverted++;
                }
                j.Commit();
            }
            catch (Exception ex)
            {
                j.RollBack();
                Rhino.RhinoApp.WriteLine($"Transaction error: {ex.Message}");
            }
        }

        a = countConverted;
    }
}

Thanks in advance!

Best,
Vishnu