你好,我是九哥~
最近发现Rhino.Inside.Revit的API手册更新了,终于可以开心的写RIR代码了,小伙伴快去试试吧,地址如下:
https://www.rhino3d.com/inside/revit/1.0/reference/rir-api
今天我们先来聊聊 Rhino 与 Revit 之间图元转换的基础知识,这些需要你牢牢记住哦,不然在 GHPython Script节点中写代码,得到的DB图元Rhino是无法处理的~
通常来讲,所有来自 Rhino几何图形和 Revit 几何图形都是无法直接互通的 ,所以它们需要与 Rhino.Inside.Revit API一起使用进行转换。
下面是引入RhinoInside.Revit几何转换的方法:
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RhinoInside.Revit")
import Autodesk.Revit.DB as DB
#引入几何图形转换方法
import RhinoInside.Revit.Convert.Geometry
clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)
接下来分别列举下一些需要转换的图元:
从Revit到Rhino
rhino_point = revit_point.ToPoint()
rhino_point2d = revit_uvpoint.ToPoint2d()
rhino_point3d = revit_point.ToPoint3d()rhino_bbox = revit_bbox.ToBoundingBox()
rhino_box = revit_bbox.ToBox()rhino_vector2d = revit_uvvector.ToVector2d()
rhino_vector3d = revit_vector.ToVector3d() rhino_plane = revit_plane.ToPlane() rhino_transform = revit_transform.ToTransform() rhino_curve = revit_line.ToCurve()
rhino_curve = revit_arc.ToCurve()
rhino_curve = revit_ellipse.ToCurve()
rhino_curve = revit_nurbsspline.ToCurve()
rhino_curve = revit_hermitespline.ToCurve()
rhino_curve = revit_helix.ToCurve()
rhino_curve = revit_curve.ToCurve()
rhino_polylinecurve = revit_polyline.ToPolylineCurve() rhino_brep = revit_solid.ToBrep() rhino_brep = revit_face.ToBrep() rhino_mesh = revit_mesh.ToMesh()rhino_curve = revit_curveloop.ToCurve()
从Rhino到Revit
revit_uvpoint = rhino_point2f.ToUV()
revit_uvpoint = rhino_point2d.ToUV() revit_uvvector = rhino_vector2f.ToUV()
revit_uvvector = rhino_vector2d.ToUV() revit_xyzpoint = rhino_point3f.ToXYZ()
revit_xyzpoint = rhino_point3d.ToXYZ() revit_xyzvector = rhino_vector3f.ToXYZ()
revit_xyzpoint = rhino_vector3d.ToXYZ() revit_plane = rhino_plane.ToPlane()revit_transform = rhino_transform.ToTransform() revit_bbox = rhino_bbox.ToBoundingBoxXYZ()
revit_bbox = rhino_box.ToBoundingBoxXYZ()revit_outline = rhino_bbox.ToOutline()revit_line = rhino_line.ToLine()
revit_polyline = rhino_polyline.ToPolyLine()
revit_arc = rhino_arc.ToArc()
revit_arc = rhino_circle.ToArc()
revit_curve = rhino_ellipse.ToCurve()
revit_curve = rhino_ellipse.ToCurve(interval) revit_point = rhino_point.ToPoint() revit_curve = rhino_linecurve.ToCurve()
revit_curve = rhino_polylinecurve.ToCurve()
revit_curve = rhino_arccurve.ToCurve()
revit_curve = rhino_nurbscurve.ToCurve()
revit_curve = rhino_polycurve.ToCurve()
revit_curve = rhino_curve.ToCurve()revit_curveloop = rhino_curve.ToCurveLoop()
revit_curvearray = rhino_curve.ToCurveArray()revit_solid = rhino_brep.ToSolid()
revit_solid = rhino_extrusion.ToSolid()
revit_solid = rhino_subd.ToSolid()
revit_solid = rhino_mesh.ToSolid() revit_mesh = rhino_brep.ToMesh()
revit_mesh = rhino_extrusion.ToMesh()
revit_mesh = rhino_subd.ToMesh()
revit_mesh = rhino_mesh.ToMesh()revit_geomobj = rhino_geom.ToGeometryObject()
简单翻了翻API,大概列举了这些转换方法,应该还有别的,小伙伴们可以自己翻翻看。
接下来,我就简单举个例子,获取图元的BoundingBox转换为可以Bake的RhinoBox:
如下图,默认Revit获取的是DB.BoundingBox,而我们需要的是Rhino的Box:
差别就是在DB.BoundingBox后面加一个.ToBoundingBox(),完整代码如下:
import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from System import Enum, Action
import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
# 还可以添加扩展方法
# 这允许在Revit对象上调用.ToXXX()转换器方法
clr.ImportExtensions(Convert.Geometry)
from Autodesk.Revit import DB
from Autodesk.Revit.DB import *if not hasattr(annotations, '__iter__'):annotations = [annotations]for anno in annotations:bbox = anno.get_BoundingBox(None).ToBoundingBox()
同样的,反过来就可以把Rhino的图元转换为Revit的图元,这里就不在演示了,小伙伴们自己尝试把~
好了,今天就是简单整理下,方便大家查找,如果你有好的想法和思路,欢迎投稿分享哦~