Calling RhinoCommon and Rhino.Inside.Revit in Python and C# Zero Touch Nodes - BoilerPlate samples

Thought this might be useful for anyone looking to make calls to Rhino.Inside or RhinoCommon in either custom Python nodes or custom C# nodes, I’ve added two example boilerplates to get started. Note that before making calls to the Rhino APIs, Rhino.Inside.Revit must be installed and running in the background otherwise the Rhino libraries can’t be accessed:

Python

import clr
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import sys
import os

roamingFolder = os.getenv('APPDATA')

rhinoInsidePath = roamingFolder + r'\Autodesk\Revit\Addins\2019\RhinoInside.Revit'

rhinoCommonPath = r'C:\Program Files\Rhino 7 WIP\System'

sys.path.append(rhinoInsidePath)
sys.path.append(rhinoCommonPath)

clr.AddReference("RhinoInside.Revit")
import RhinoInside
from RhinoInside.Revit.Convert.Geometry import *

clr.AddReference("RhinoCommon")
import Rhino
from Rhino.Geometry import *

doc = DocumentManager.Instance.CurrentDBDocument

#Uncomment the line below to enable the first input
#t = UnwrapElement(IN[0])

# "Start" the transaction
#TransactionManager.Instance.EnsureInTransaction(doc)

# "End" the transaction
#TransactionManager.Instance.TransactionTaskDone()

#Uncomment the line below to output an object
#OUT = t

C# (zero touch import)
Reference the following libraries to do pretty much anything you need:
image

using Autodesk.Revit.DB;
using Revit.GeometryConversion;
using RevitServices.Persistence;
using Rhino.Geometry;
using RhinoInside.Revit.Convert.Geometry;

namespace DynamoNodes.RhinoInside
{
    public class RhinoInsideNode
    {
        public RhinoInsideNode(bool refresh)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            // Write your code here.
        }
    }
}
7 Likes

@Thomas_Mahon if you import the os module and use “os.getenv(“APPDATA”)” this will give you the path to the current users roaming folder then no need to update it with user locations.

Wouldnt a similar approach be needed for the revit version as well?

Example can be found in this code:

2 Likes

@Brendan_Cassidy good tip - with Python I always resort to the bare-minimum as its only ever used for rapid prototyping in all of my cases, never production-code, which is why I’m kind of indifferent to this. Nevertheless, this is very useful for Python developers and I’ll modify the boilerplate.

Well, I guess yeah you could also address the fact the boilerplate is targeting Revit 2019 but now its getting anal - whats stopping whoever is using it from simply modifying this themselves? It is just a simple boilerplate to get started that’s all, plus a boilerplate is designed to be modified to suit the dev’s needs…anyway, enjoy!

1 Like