COMPAS integration

RV2 bundles the following COMPAS packages:

When you install RV2 using the installer, these packages are installed in a miniconda environment and registered in Rhino. It is the same as the "normal" installation process of COMPAS packages, but automated. Also the command plugin is installed with an automated version of the typical installation process for COMPAS-based Rhino command plugins.

Use COMPAS packages in a Rhino script

This means that the COMPAS packages listed above (with the exception of compas_triangle) are also available in the Rhino PythonScript Editor. To verify this, simply open the editor and run the following snippet:

import compas
print compas.__version__

# 0.16.0

Note that Rhino uses IronPython 2.7.8. Therefore print statements are still in the "old" Python 2x format...

In this final tutorial, we will use these packages to extend the functionality of RV2 with custom Python scripts. For communication between these scripts and RV2, we will use the *.rv2 session files.

Load Form Diagram From Session File

To load a Form Diagram from a RV2 session file and visualise it in a script, you could do the following:

import json

from compas.utilities import DataDecoder
from compas_rv2.datastructures import FormDiagram
from compas_rv2.scene import Scene

with open('bm-3.rv2', 'r') as f:
    session = json.load(f, cls=DataDecoder)

form = FormDiagram.from_data(session['data']['form'])

scene = Scene()
scene.settings = session['settings']
scene.add(form, name='form')
scene.update()

Save the script in the same directoy as the session file ('bm-3.rv2'), or provide the full path to the session file. Otherwise Rhino will not be able to find it.

Extract data

To extract information from the Form Diagram you can simply use the typical COMPAS mechanisms for extracting data out of meshes.

for vertex in mesh.vertices():
    xyz = mesh.vertex_attributes(vertex, 'xyz')

XY = mesh.vertices_attributes('xy')
Z = mesh.vertices_attribute('z')    

Using the data and attribute "accessors", we can for example extract the values of the reaction forces at the supports, or the axial forces in the edges.

for vertex in form.vertices_where({'is_anchor': True}):
    reaction = form.vertex_attributes(vertex, ['_rx', '_ry', '_rz'])
    
for edge in form.edges_where({'_is_edge': True}):
    force = form.edge_attribute(edge, '_f')

With this we can, for example, compute a rough approximation of the (lumped) stress at the nodes.

for vertex in form.vertices():
    stresses = []
    for nbr in form.vertex_neighbors(vertex):
        left = form.halfedge_face(vertex, nbr)
        right = form.halfedge_face(nbr, vertex)
        if left and right:
            if form.face_attribute(left, '_is_loaded') and form.face_attribute(right, '_is_loaded'):
                a = form.face_centroid(left)
                b = form.face_centroid(right)
                w = distance_point_point(a, b)
                f = form.edge_attribute((vertex, nbr), '_f')
                s = f / w  # assuming a thickness of "1"
                stresses.append(s)
    S = sum(stresses) / len(stresses)

Last updated