A1. Import

Import a surface geometry from rhino and convert to a compas mesh.

Objectives

You will learn how to import a surface geometry from Rhino and convert it to a compas mesh data structure. This also includes setting the file paths to serialise the data structure to a JSON file and visualising it.

Rhino Surface

The surface we want to import from Rhino is in the Rhino file in the data folder in the package you downloaded in A. Form Finding.

It is actually a polysurface that is already subdivided with appropriate spacings. The generation of such is excluded from the scope of this course.

Paths

First, we set the paths to the data folder that exists on the same level as the A form finding, B advanced form finding, and C fabrication folder. This way, we can store the data there in the subsequent weeks on cable nets & membranes.

# ==============================================================================
# Paths
# ==============================================================================

HERE = os.path.dirname(__file__)
DATA = os.path.abspath(os.path.join(HERE, '..', 'data'))
FILE_O = os.path.join(DATA, 'cablenet_import.json')

Import from Rhino

Second, we can import the surface from Rhino by selecting the surface, wrapping it as a RhinoSurface, and converting the surface to a COMPAS mesh. This we will wrap inside a function and that we then call.

# ==============================================================================
# Helpers
# ==============================================================================

def mesh_from_rhinosurface():
    """Make a mesh from a Rhino surface.
    """

    guid = compas_rhino.select_surface()
    surface = RhinoSurface.from_guid(guid)
    mesh = surface.to_compas(Mesh)
    return mesh
# ==============================================================================
# Import from Rhino
# ==============================================================================

mesh = mesh_from_rhinosurface()

Visualise in Rhino

Third, we can visualise the generated mesh in Rhino together with its vertex and face labels to better understand the generated data structure.

# ==============================================================================
#  Visualize
# ==============================================================================

artist = MeshArtist(mesh, layer="CSD2::A1::Import")
artist.clear_layer()
artist.draw_vertexlabels()
artist.draw_facelabels()
artist.draw()

Export

Last, we can export the mesh data structure by serialising it to a JSON file. This will generate a file that you will see in the data folder, both in your Finder or in VS Code:

Last updated