Rhino.Inside Revit

Hey there! I have just started messing around with C# script components for Rhino.Inside Revit. I followed the instructions found here
https://www.rhino3d.com/inside/revit/beta/guides/rir-csharp
But I immediately get an error that
“RhinoInside.Revit.Revit does not contain a definition for ‘EnqueueAction’”
if you take away the second ‘Revit’ either in the code or in the assembly call, it gives “The type or namespace… does not exist”
This is Rhino 7 in Revit 2020.2.
Have the libraries changed since that blog post?
I would love some help! Lots of power in this if we can get it working!
thanks for your help!
daniel

1 Like

Hi @d.c.segraves,

Wee need to update that section, EnqueueAction is no more available.
Here an updated sample

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using RhinoInside.Revit;
using RhinoInside.Revit.Convert.Geometry;
using DB = Autodesk.Revit.DB;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(bool Trigger, double Radius, ref object Sphere)
  {
    if(Trigger == false) return;
    if(Radius < Revit.VertexTolerance * 10.0) return;

    var doc = Revit.ActiveDBDocument;
    using(var tx = new DB.Transaction(doc, Component.NickName))
    {
      tx.Start();
      Sphere = CreateSphere(doc, Radius);
      tx.Commit();
    }
  }

  // <Custom additional code> 
  private DB.DirectShape CreateSphere(DB.Document doc, double radius)
  {
    var sphere = new Rhino.Geometry.Sphere(Rhino.Geometry.Point3d.Origin, radius);
    var brep = sphere.ToBrep();

    var revitCategory = new DB.ElementId((int) DB.BuiltInCategory.OST_GenericModel);

    var ds = DB.DirectShape.CreateElement(doc, revitCategory);
    var shapeList = new List<DB.GeometryObject>() { brep.ToSolid() };
    ds.AppendShape(shapeList);
    return ds;
  }
  // </Custom additional code> 
}
2 Likes

Yessssss. Hey Kike! Thank you! Works! (with a couple little changes, see below)

if(Trigger == false) return;
if(Radius < Revit.VertexTolerance * 10.0) return;

var doc = Revit.ActiveDBDocument;
using(var tx = new DB.Transaction(doc, Component.NickName))
{
  tx.Start();
  Sphere = CreateSphere(doc, Radius);
  tx.Commit();
}

//

private object CreateSphere(DB.Document doc, double radius) {
// convert the sphere into Brep
var sphere = new Rhino.Geometry.Sphere(Rhino.Geometry.Point3d.Origin, radius);
var brep = sphere.ToBrep();

var revitCategory = new DB.ElementId((int) DB.BuiltInCategory.OST_GenericModel);

var ds = DB.DirectShape.CreateElement(doc, revitCategory);
var shapeList = new List<DB.GeometryObject>() { brep.ToSolid() };
ds.AppendShape(shapeList);
return ds;

}

One other quick one - which side has the older assembly? (The one I’m referencing or the one GH.Inside is picking up?..) Will this ever be an issue or should I ignore?

1 Like

I think is about the assembly RiR references.

But let me confirm it an see if we can remove it.

1 Like