geometry

Wrappers for Rhino objects that can be used to convert Rhino geometry and data to COMPAS objects.

import compas_rhino
from compas_rhino.geometry import RhinoMesh

guid = compas_rhino.select_mesh()
mesh = RhinoMesh.from_guid(guid).to_compas()

BaseRhinoGeometry

class compas_rhino.geometry.BaseRhinoGeometry[source]

Bases: object

Base class for Rhino geometry objects.

Attributes

name (str) – The name of the object.

abstract classmethod from_geometry(geometry)
classmethod from_guid(guid)

Construct a Rhino object wrapper from the GUID of an existing Rhino object.

Parameters

guid (str) – The GUID of the Rhino object.

Returns

compas_rhino.geometry.BaseRhinoGeometry – The Rhino object wrapper.

classmethod from_object(obj)

Construct a Rhino object wrapper from an existing Rhino object.

Parameters

obj (Rhino.DocObjects.RhinoObject) – The Rhino object.

Returns

compas_rhino.geometry.BaseRhinoGeometry – The Rhino object wrapper.

abstract classmethod from_selection()
to_compas(cls=None)[source]
transform(T)[source]

Transform the Rhino object.

Parameters

T (compas.geometry.Transformation or Rhino.Geomtry.Transform) – The transformation matrix.

Returns

None – The Rhino object is transformed in place.


RhinoPoint

class compas_rhino.geometry.RhinoPoint[source]

Wrapper for Rhino point objects.

Attributes
  • x (read-only) (float) – The X coordinate.

  • y (read-only) (float) – The Y coordinate.

  • z (read-only) (float) – The Z coordinate.

  • xyz (read-only) (list) – The XYZ coordinates.

classmethod from_geometry(geometry)

Construct a point wrapper from an existing geometry object.

Parameters

geometry (point or Rhino.Geometry.Point3d) – The input geometry.

Returns

compas_rhino.geometry.RhinoPoint – The wrapped point.

classmethod from_selection()

Construct as point wrapper from a selected point object.

Parameters

None

Returns

compas_rhino.geometry.RhinoPoint – The wrapped point.

to_compas()[source]

Convert the wrapper to a COMPAS point.

Returns

compas.geometry.Point – A COMPAS point.


RhinoVector

class compas_rhino.geometry.RhinoVector[source]

Wrapper for a Rhino vector objects.

Attributes
  • x (read-only) (float) – The X coordinate.

  • y (read-only) (float) – The Y coordinate.

  • z (read-only) (float) – The Z coordinate.

  • xyz (read-only) (list) – The XYZ coordinates.

classmethod from_geometry(geometry)

Construct a vector wrapper from an existing geometry object.

Parameters

geometry (vector or Rhino.Geometry.Point3d or Rhino.Geometry.Vector3d) – The input geometry.

Returns

compas_rhino.geometry.RhinoVector – The wrapped vector.

classmethod from_selection()
to_compas()[source]

Convert the wrapper to a COMPAS object.

Returns

compas.geometry.Vector – The COMPAS vector.


RhinoLine

class compas_rhino.geometry.RhinoLine[source]

Wrapper for a Rhino line objects.

Attributes
  • start (read-only) (Rhino.Geometry.Point3d) – The starting point of the line.

  • end (read-only) (Rhino.Geometry.Point3d) – The end point of the line.

classmethod from_geometry(geometry)

Construct a line from an existing Rhino line geometry object.

Parameters

geometry (two points or Rhino.Geometry.Line) – The input geometry.

classmethod from_selection()

Construct a line wrapper by selecting an existing Rhino line object.

Parameters

None

Returns

compas_rhino.geometry.RhinoLine – The wrapped line.

to_compas()[source]

Convert the line to a COMPAS geometry object.

Returns

compas.geometry.Line – The equivalent COMPAS geometry line.


RhinoPlane

class compas_rhino.geometry.RhinoPlane[source]

Wrapper for a Rhino plane objects.

Attributes
  • point (read-only) (Rhino.Geometry.Point3d) – Base point of the plane.

  • normal (read-only) (Rhino.Geometry.Vector3d) – The normal vector of the plane.

  • xaxis (read-only) (Rhino.Geometry.Vector3d) – The X axis of the plane.

  • yaxis (read-only) (Rhino.Geometry.Vector3d) – The Y axis of the plane.

Notes

In Rhino, a plane and a frame are equivalent. Therefore, the COMPAS conversion function of this class returns a frame object instead of a plane.

classmethod from_geometry(geometry)

Construct a plane wrapper from an existing geometry object.

Parameters

geometry (tuple of point and normal or Rhino.Geometry.Plane or compas.geometry.Plane or compas.geometry.Frame) – The geometry object defining a plane.

Returns

compas_rhino.geometry.RhinoPlane – The wrapped plane.

classmethod from_selection()
to_compas()[source]

Convert to a COMPAS geometry object.

Returns

compas.geometry.Frame – A COMPAS frame object.


RhinoMesh

class compas_rhino.geometry.RhinoMesh[source]

Wrapper for Rhino mesh objects.

Attributes
  • vertices (read-only) (list of point) – The coordinates of the vertices of the mesh.

  • faces (read-only) (list of list of int) – Faces defined as lists of references into the list of vertices.

  • vertex_color (list) – The colors of the vertices. Setting this to None unsets the vertex colors.

  • border (read-only) (list) – The GUIDs of the border curves.

classmethod from_geometry(geometry)

Construct a mesh wrapper from an existing Rhino geometry object.

Parameters

geometry (Rhino.Geometry.Mesh) – A Rhino mesh geometry.

Returns

compas_rhino.geometry.RhinoMesh – The wrapped line.

classmethod from_selection()

Construct a mesh wrapper by selecting an existing Rhino mesh object.

Parameters

None

Returns

compas_rhino.geometry.RhinoMesh – The wrapped line.

to_compas(cls=None)[source]

Convert a Rhino mesh to a COMPAS mesh.

Parameters

cls (compas.datastructures.Mesh, optional) – The mesh type.

Returns

compas.datastructures.Mesh – The equivalent COMPAS mesh.


RhinoCurve

class compas_rhino.geometry.RhinoCurve[source]

Wrapper for Rhino curve objects.

Parameters

None

Attributes
  • start (read-only) (Rhino.Geometry.Point3d) – The start point of the curve.

  • end (read-only) (Rhino.Geometry.Point3d) – The end point of the curve.

  • points (read-only) (list of RhinoGeometry.Point3d) – List of points between start and end, defining the geometry of the curve.

Examples

>>> rhinocurve = RhinoCurve.from_guid(guid)
>>> curve = rhinocurve.to_compas()
>>> if rhinocurve.is_line():
...     isinstance(curve, compas.geometry.Line)
...
True
>>> if rhinocurve.is_polyline():
...     isinstance(curve, compas.geometry.Polyline)
...
True
classmethod from_geometry(geometry)
classmethod from_selection()

Construct a curve wrapper by selecting an existing Rhino curve object.

Parameters

None

Returns

compas_rhino.geometry.RhinoCurve – The wrapped curve.

to_compas()[source]

Convert the curve to an equivalent geometry object.

Returns


RhinoSurface

class compas_rhino.geometry.RhinoSurface[source]

Wrapper for Rhino surface objects.

classmethod from_geometry()
classmethod from_selection()
to_compas(cls=None, facefilter=None, cleanup=True)[source]

Convert the surface b-rep loops to a COMPAS mesh.

Parameters
  • cls (compas.datastructures.Mesh, optional) – The type of COMPAS mesh.

  • facefilter (callable, optional) – A filter for selection which Brep faces to include. If provided, the filter should return True or False per face. A very simple filter that includes all faces is def facefilter(face): return True. Default parameter value is None in which case all faces are included.

  • cleanup (bool, optional) – Flag indicating to clean up the result. Cleaning up means to remove isolated faces and unused vertices. Default is True.

Returns

compas.datastructures.Mesh – The resulting mesh.

Examples

>>> import compas_rhino
>>> from compas_rhino.geometry import RhinoSurface
>>> from compas_rhino.artists import MeshArtist
>>> def facefilter(face):
...     success, w, h = face.GetSurfaceSize()
...     if success:
...         if w > 10 and h > 10:
...             return True
...     return False
...
>>> guid = compas_rhino.select_surface()
>>> surf = RhinoSurface.from_guid(guid)
>>> mesh = surf.to_compas(facefilter=facefilter)
>>> artist = MeshArtist(mesh, layer="Blocks")
>>> artist.clear_layer()
>>> artist.draw()