Transaction Failure in Scripted C# Component

Hi,

There is a conflict with Revit MFC context and Rhino MFC context.
We are working to fix this in Rhino.

But meanwhile there is a method called RhinoInside.Revit.Rhinoceros.InvokeInHostContext that should help here.
As EnqueueAction InvokeInHostContext is a temporary workaround.
EnqueAction was there when RiR was unable to keep the Revit API context, now is no more needed and will be removed. Same will happen to InvokeInHostContext once we address this.

public class Script_Instance : GH_ScriptInstance
{
  private void RunScript(Curve Curve, object Type, object Level, ref object Railing)
  {
    if(Curve == null || Type == null || Level == null)
      return;

    Railing = RhinoInside.Revit.Rhinoceros.InvokeInHostContext
    (
      () => CreateRailing(Revit.ActiveDBDocument, Curve.ToCurveLoop(), Type as DB.ElementType, Level as DB.Level)
    );
  }

  private DB.Architecture.Railing CreateRailing(DB.Document doc, DB.CurveLoop curveLoop, DB.ElementType type, DB.Level level)
  {
    DB.Architecture.Railing result = null;
    using(var transaction = new DB.Transaction(doc, Component.Name))
    {
      transaction.Start();

      result = DB.Architecture.Railing.Create(doc, curveLoop, type.Id, level.Id);

      transaction.Commit();
    }

    return result;
  }
}

Here RiR-CreateRailing.gh (26.4 KB) the Grasshopper definition with a sample on using this method.