Using Rhino Curves in Python RIR

Hi guys,

How can I use Rhino curves in RIR Python environment? I want to create something out of Rhino curves using Revit API. How can I convert Rhino curves to Revit compatible curves through RhinoInside.Revit library?

An example would be great. Thanks.

We need to create some documentation for this, but here a sample.

RiR-ConvertGeometry.gh (13.3 KB)

Please remember to adjust Type Hint on inputs from the context menu.

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RhinoInside.Revit")

import RhinoInside
clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

if _point is not None:
    point_ = _point.ToXYZ()

if _curve is not None:
    curve_ = _curve.ToCurve()

if _box is not None:
    box_ = _box.ToBoundingBoxXYZ()

if _brep is not None:
    solid_ = _brep.ToSolid()

Yes, documentation is definitely needed. I have tried ToCurve() method but got the following error.

  1. Solution exception:‘NoneType’ object has no attribute ‘ToCurve’

Any idea why?

import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')
clr.AddReference("System")

from System import Enum
from System.Collections.Generic import List

import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
from Autodesk.Revit import DB

clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

# access the active document object
doc = Revit.ActiveDBDocument

def show_warning(msg):
    ghenv.Component.AddRuntimeMessage(RML.Warning, msg)

def show_error(msg):
    ghenv.Component.AddRuntimeMessage(RML.Error, msg)

def show_remark(msg):
    ghenv.Component.AddRuntimeMessage(RML.Remark, msg)

curves = List[DB.Curve]()
curves.Add(Curve.ToCurve())

clc = DB.CurveLoop.Create(curves)


#Create and Start Transaction
t = DB.Transaction(doc, "Create Ceiling")
t.Start()
try:
    ceiling = DB.Ceiling.Create(doc, curves, Type.Id, Level.Id)
    t.Commit()
except Exception as txn_err:
    show_error(str(txn_err))
    t.RollBack()

I am trying to create a ceiling from a given single curve outline. I am quite new in Revit API. If I have any noob mistakes, just forgive :slight_smile:

I got the same error from the definition you shared.

where is the Curve in curves.Add(Curve.ToCurve()) object coming from?

image

It is the curve input in the Python node. I got the same error in the definition that kike shared though.

Hi @mucahitbgoker,

I edited the previous post to check if the user has something plugged in the component.

Now it should not show any error even if you don’t connect anything.

Hi @kike,

I get the following error.

  1. Solution exception:Failed to convert non G1 continuous curve.

I connected a simple rectangle as an input in your definition.

When I tried it with my script, I get this error too:

  1. Solution exception:Failed to convert non G1 continuous curve.

I see,

You are trying to convert a boundary to create the ceiling.

Since Revit curves should be C2 you can not convert a curve with kinks to a Revit Curve.

On these cases you should use ToCurveLoop or ToCurveArray depending on where you like to use the result.

Celing.Create takes a CurveLoop.
https://apidocs.co/apps/revit/2022/63030aa3-d58d-b830-db18-0882c5990507.htm

So you need ToCurveLoop here to convert each loop.

Thanks @kike. Now I can use curves to create ceiling. Can I achieve element binding in Python component though? Whenever a change happens in the Grasshopper environment, it recreates a ceiling.

Right now there is no API for Element Tracking.
We want to be sure this implementation works for the users before release it to a wider audience.

But will be available on an upcoming release.

1 Like

Okidoki @kike. Thank you!:vulcan_salute:

About documentation you may use the source code itself.

Here you have conversion from Rhino to Revit.
rhino.inside-revit/GeometryEncoder.cs

And here from Revit to Rhino.
rhino.inside-revit/GeometryDecoder.cs

Searching “public static” should give you an idea of what is available.

@kike-asuni Any example for c# that you can share please?