Skip to content

compas_cem.ghpython ¤

Grasshopper components and scene objects that draw diagrams inside Rhino.

Classes¤

DiagramObject ¤

A scene object that draws a diagram in Grasshopper.

Notes

Every draw method takes an explicit selection, because the Grasshopper components expose the selection as a component input. Drawing returns bare Rhino geometry and carries no color, so the coloring is left to whatever consumes the geometry downstream.

Node positions are read from the scene object rather than from the diagram, so a transformation set on the object applies to everything it draws.

Attributes¤

diagram property ¤
diagram

The diagram this object draws.

Methods:¤

draw_edges ¤
draw_edges(edges=None)

Draw a selection of edges.

Parameters:

  • edges

    The edges to draw. If None, every edge is drawn.

Returns:

  • lines

    One Rhino line per drawn edge.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_edges(self, edges=None):
    """
    Draw a selection of edges.

    Parameters
    ----------
    edges :
        The edges to draw. If `None`, every edge is drawn.

    Returns
    -------
    lines :
        One Rhino line per drawn edge.
    """
    edges = self.diagram.edges() if edges is None else edges
    node_xyz = self.node_xyz

    return [line_to_rhino((node_xyz[u], node_xyz[v])) for u, v in edges]
draw_loads ¤
draw_loads(nodes=None, scale=1.0, gap=0.0, min_load=0.001)

Draw the loads applied to a selection of nodes.

Parameters:

  • nodes

    The nodes to draw the loads of. If None, every node is taken.

  • scale

    The factor to scale the load vectors by.

  • gap

    The offset between a node and the load drawn at it.

  • min_load

    The smallest load magnitude worth drawing.

Returns:

  • lines

    One Rhino line per drawn load.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_loads(self, nodes=None, scale=1.0, gap=0.0, min_load=1e-3):
    """
    Draw the loads applied to a selection of nodes.

    Parameters
    ----------
    nodes :
        The nodes to draw the loads of. If `None`, every node is taken.
    scale :
        The factor to scale the load vectors by.
    gap :
        The offset between a node and the load drawn at it.
    min_load :
        The smallest load magnitude worth drawing.

    Returns
    -------
    lines :
        One Rhino line per drawn load.
    """
    nodes = list(self.diagram.nodes()) if nodes is None else list(nodes)
    shift = {node: False for node in nodes}

    return self._draw_forces(
        nodes=nodes,
        attr_names=["qx", "qy", "qz"],
        scale=scale,
        shift=shift,
        gap=gap,
        tol=min_load,
    )
draw_nodes ¤
draw_nodes(nodes=None)

Draw a selection of nodes.

Parameters:

  • nodes

    The nodes to draw. If None, every node is drawn.

Returns:

  • points

    One Rhino point per drawn node.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_nodes(self, nodes=None):
    """
    Draw a selection of nodes.

    Parameters
    ----------
    nodes :
        The nodes to draw. If `None`, every node is drawn.

    Returns
    -------
    points :
        One Rhino point per drawn node.
    """
    nodes = self.diagram.nodes() if nodes is None else nodes
    node_xyz = self.node_xyz

    return [point_to_rhino(node_xyz[node]) for node in nodes]
draw_nodes_support ¤
draw_nodes_support(nodes=None)

Draw a selection of the support nodes of the diagram.

Parameters:

  • nodes

    The nodes to draw, of which only the supports are kept. If None, every support node is drawn.

Returns:

  • points

    One Rhino point per drawn support node.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_nodes_support(self, nodes=None):
    """
    Draw a selection of the support nodes of the diagram.

    Parameters
    ----------
    nodes :
        The nodes to draw, of which only the supports are kept. If `None`,
        every support node is drawn.

    Returns
    -------
    points :
        One Rhino point per drawn support node.
    """
    nodes = self._selected_keys("support_nodes", "is_node_support", nodes)

    return self.draw_nodes(nodes)

FormDiagramObject ¤

A scene object that draws a form diagram in Grasshopper.

Attributes¤

form property ¤
form

The form diagram this object draws.

Methods:¤

draw_reactions ¤
draw_reactions(nodes=None, scale=1.0, gap=0.0, min_force=0.001)

Draw the reaction forces at a selection of support nodes.

Parameters:

  • nodes

    The nodes to draw the reaction forces of. If None, every node is taken.

  • scale

    The factor to scale the reaction forces by.

  • gap

    The offset between a node and the reaction force drawn at it.

  • min_force

    The smallest reaction force magnitude worth drawing.

Returns:

  • lines

    One Rhino line per drawn reaction force.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_reactions(self, nodes=None, scale=1.0, gap=0.0, min_force=1e-3):
    """
    Draw the reaction forces at a selection of support nodes.

    Parameters
    ----------
    nodes :
        The nodes to draw the reaction forces of. If `None`, every node is
        taken.
    scale :
        The factor to scale the reaction forces by.
    gap :
        The offset between a node and the reaction force drawn at it.
    min_force :
        The smallest reaction force magnitude worth drawing.

    Returns
    -------
    lines :
        One Rhino line per drawn reaction force.
    """
    nodes = list(self.form.nodes()) if nodes is None else list(nodes)

    return self._draw_forces(
        nodes=nodes,
        attr_names=["rx", "ry", "rz"],
        scale=scale,
        shift=self._reaction_shifts(nodes),
        gap=gap,
        tol=min_force,
    )

TopologyDiagramObject ¤

A scene object that draws a topology diagram in Grasshopper.

Attributes¤

topology property ¤
topology

The topology diagram this object draws.

Methods:¤

draw_edges_deviation ¤
draw_edges_deviation(edges=None)

Draw a selection of the deviation edges of the topology diagram.

Parameters:

  • edges

    The edges to draw, of which only the deviations are kept. If None, every deviation edge is drawn.

Returns:

  • lines

    One Rhino line per drawn deviation edge.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_edges_deviation(self, edges=None):
    """
    Draw a selection of the deviation edges of the topology diagram.

    Parameters
    ----------
    edges :
        The edges to draw, of which only the deviations are kept. If
        `None`, every deviation edge is drawn.

    Returns
    -------
    lines :
        One Rhino line per drawn deviation edge.
    """
    edges = self._selected_keys("deviation_edges", "is_deviation_edge", edges)

    return self.draw_edges(edges)
draw_edges_trail ¤
draw_edges_trail(edges=None)

Draw a selection of the trail edges of the topology diagram.

Parameters:

  • edges

    The edges to draw, of which only the trails are kept. If None, every trail edge is drawn.

Returns:

  • lines

    One Rhino line per drawn trail edge.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_edges_trail(self, edges=None):
    """
    Draw a selection of the trail edges of the topology diagram.

    Parameters
    ----------
    edges :
        The edges to draw, of which only the trails are kept. If `None`,
        every trail edge is drawn.

    Returns
    -------
    lines :
        One Rhino line per drawn trail edge.
    """
    edges = self._selected_keys("trail_edges", "is_trail_edge", edges)

    return self.draw_edges(edges)
draw_nodes_origin ¤
draw_nodes_origin(nodes=None)

Draw a selection of the origin nodes of the topology diagram.

Parameters:

  • nodes

    The nodes to draw, of which only the origins are kept. If None, every origin node is drawn.

Returns:

  • points

    One Rhino point per drawn origin node.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_nodes_origin(self, nodes=None):
    """
    Draw a selection of the origin nodes of the topology diagram.

    Parameters
    ----------
    nodes :
        The nodes to draw, of which only the origins are kept. If `None`,
        every origin node is drawn.

    Returns
    -------
    points :
        One Rhino point per drawn origin node.
    """
    nodes = self._selected_keys("origin_nodes", "is_node_origin", nodes)

    return self.draw_nodes(nodes)
draw_trails ¤
draw_trails()

Draw the trails of the topology diagram.

Returns:

  • curves

    One Rhino polyline curve per trail.

Notes

A polyline curve is drawn rather than a polyline, because Grasshopper unpacks a bare polyline output into its points.

Source code in src/compas_cem/ghpython/scene_objects.py
def draw_trails(self):
    """
    Draw the trails of the topology diagram.

    Returns
    -------
    curves :
        One Rhino polyline curve per trail.

    Notes
    -----
    A polyline curve is drawn rather than a polyline, because Grasshopper
    unpacks a bare polyline output into its points.
    """
    node_xyz = self.node_xyz

    curves = []
    for trail in self.topology.trails():
        points = [node_xyz[node] for node in trail]
        curves.append(polyline_to_rhino_curve(points))

    return curves