Example #1
0
import os
from compas_fofin.datastructures import Cablenet
from compas_fofin.rhino import CablenetArtist
from compas.rpc import Proxy

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '..', '..', 'data')
FILE = os.path.join(DATA, 'saddle.obj')

proxy = Proxy('compas_fofin.equilibrium')

cablenet = Cablenet.from_obj(FILE)
cablenet.set_vertices_attribute('is_anchor', True, keys=cablenet.vertices_where({'vertex_degree': 1}))

result = proxy.cablenet_fd_rpc(cablenet.to_data())
cablenet.data = result

artist = CablenetArtist(cablenet, layer="FoFin::Cablenet")
artist.clear_layer()
artist.draw_vertices()
artist.draw_edges()
artist.draw_forces(scale=0.05)
artist.draw_loads()
artist.draw_reactions()
artist.redraw()
import os

from compas_ags.diagrams import FormGraph
from compas_ags.diagrams import FormDiagram
from compas_ags.diagrams import ForceDiagram
from compas_ags.rhino import Scene

from compas.rpc import Proxy

graphstatics = Proxy('compas_ags.ags.graphstatics')
graphstatics.stop_server()
graphstatics.start_server()

# this file has unloaded, 2-valent nodes
# they will be removed automatically
# and the result renumbered
HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, '../data/debugging/zero.obj')

graph = FormGraph.from_obj(FILE)
form = FormDiagram.from_graph(graph)
force = ForceDiagram.from_formdiagram(form)

# fix the supports
form.vertices_attribute('is_fixed', True, [8, 7])

# set the loads
form.edge_force((0, 1), +10.0)
form.edge_force((2, 3), +10.0)
form.edge_force((4, 5), +10.0)
Example #3
0
import compas
import compas_rhino
from compas.datastructures import Mesh
from compas.rpc import Proxy
from compas_rhino.artists import MeshArtist

numerical = Proxy('compas.numerical')
fd_numpy = numerical.fd_numpy

compas_rhino.clear()

mesh = Mesh.from_obj(compas.get('faces.obj'))

mesh.update_default_vertex_attributes(is_anchor=False)
mesh.update_default_vertex_attributes(px=0.0, py=0.0, pz=0.0)
mesh.update_default_vertex_attributes(rx=0.0, ry=0.0, rz=0.0)

mesh.update_default_edge_attributes(q=1.0, f=0.0, l=0.0)

corners = list(mesh.vertices_where({'vertex_degree': 2}))
mesh.vertices_attribute('is_anchor', True, keys=corners)
mesh.vertices_attribute('z', 7.0, keys=[0, 35])
mesh.edges_attribute('q', 10, keys=list(mesh.edges_on_boundary()))

key_index = mesh.key_index()
xyz = mesh.vertices_attributes('xyz')
loads = mesh.vertices_attributes(('px', 'py', 'pz'))
fixed = [key_index[key] for key in mesh.vertices_where({'is_anchor': True})]
edges = [(key_index[u], key_index[v]) for u, v in mesh.edges()]
q = mesh.edges_attribute('q')
import os

#construct the mesh
box = Box(Frame.worldXY(), 500, 100, 100)
box_mesh = Mesh.from_vertices_and_faces(box.vertices, box.faces)

box_2 = Box(([250, 20, 20], [300, 0, 100], [0, 100, 0]), 100, 50, 80)
box_mesh_2 = Mesh.from_vertices_and_faces(box_2.vertices, box_2.faces)

#call function
python_exe_path = 'C:\ProgramData\Anaconda3\envs\compas_assembly\python.exe'
import sys
python_exe_path = sys.executable

with Proxy(package='Trimesh_proxy', python=python_exe_path) as f:
    result = f.trimesh_subtract(box_mesh, box_mesh_2)
    result_mesh = Mesh.from_data(result['value'])

# print (result_mesh)

# import os
# HERE = os.path.dirname(_file_)
# DATA = os.path.abspath(os.path.join(HERE, '..', 'data'))
# FILE_O = os.path.join(DATA, 'compas_boolean_test_2.json')
# result.to_json(FILE_O, pretty=True)

# mesh = Mesh.from_json(FILE_I)

artist = MeshArtist(result_mesh, layer='Layer1')
artist.draw_vertices()
Example #5
0
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import os

from compas.rpc import Proxy

from compas_ags.diagrams import FormGraph
from compas_ags.diagrams import FormDiagram
from compas_ags.diagrams import ForceDiagram

from compas_ags.rhino import FormObject
from compas_ags.rhino import ForceObject

graphstatics = Proxy('compas_ags.ags.graphstatics')

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '../data')
FILE = os.path.join(DATA, 'debugging', 'truss.obj')

graph = FormGraph.from_obj(FILE)

form = FormDiagram.from_graph(graph)
force = ForceDiagram.from_formdiagram(form)

form.edge_force((0, 1), -1.0)
form.edge_force((2, 3), -1.0)
form.edge_force((4, 5), -1.0)

form.data = graphstatics.form_update_q_from_qind_proxy(form.data)
from compas.geometry import add_vectors
from compas.geometry import intersection_line_plane
from compas.geometry import Frame
from compas.geometry import bounding_box
from compas.geometry import bounding_box_xy
from compas.geometry import cross_vectors
from compas.geometry import subtract_vectors
from compas.geometry import normalize_vector
from compas.geometry import scale_vector
from compas.geometry import offset_polygon
from compas.rpc import Proxy

from compas_fofin.datastructures import Shell
from compas_fofin.rhino import ShellArtist

numerical = Proxy('compas.numerical')

# ==============================================================================
# Initialise
# ==============================================================================

HERE = os.path.dirname(__file__)
DATA = os.path.abspath(os.path.join(HERE, '..', 'data'))
FILE_I = os.path.join(DATA, 'data.json')
FILE_O = os.path.join(DATA, 'data-fabrication-cables.xlsx')

shell = Shell.from_json(FILE_I)

# ==============================================================================
# Beam vertices
# ==============================================================================
Example #7
0
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import scriptcontext as sc
import traceback

from compas.rpc import Proxy

proxy = Proxy('compas_rbe.equilibrium')
compute_interface_forces_xfunc = proxy.compute_interface_forces_xfunc


def compute_interface_forces(assembly, solver):
    data = {
        'assembly': assembly.to_data(),
        'blocks':
        {str(key): assembly.blocks[key].to_data()
         for key in assembly.blocks}
    }
    result = compute_interface_forces_xfunc(data, solver=solver)
    assembly.data = result['assembly']
    for key in assembly.blocks:
        assembly.blocks[key].data = result['blocks'][str(key)]


__commandname__ = "Assembly_compute_interface_forces"


def RunCommand(is_interactive):
    try:
Example #8
0
from compas.geometry import Point
from compas.geometry import Box
from compas.geometry import Sphere
from compas.datastructures import Mesh

from compas_rhino.artists import MeshArtist

from compas.rpc import Proxy

proxy = Proxy()

# ==============================================================================
# Make a box and a sphere
# ==============================================================================

box = Box.from_width_height_depth(2, 2, 2)
box = Mesh.from_shape(box)
box.quads_to_triangles()

A = box.to_vertices_and_faces()

sphere = Sphere(Point(1, 1, 1), 1)
sphere = Mesh.from_shape(sphere, u=30, v=30)
sphere.quads_to_triangles()

B = sphere.to_vertices_and_faces()

# ==============================================================================
# Remesh the sphere
# ==============================================================================
Example #9
0
from compas.geometry import scale_vector
from compas.geometry import Point
from compas.geometry import Vector
from compas.geometry import Plane
from compas.geometry import Polyline
from compas.geometry import Rotation
from compas.geometry import Translation
from compas.geometry import Scale
from compas.datastructures import Mesh

from compas_rhino.artists import MeshArtist
from compas_rhino.artists import PolylineArtist

from compas.rpc import Proxy

slicer = Proxy('compas_cgal.slicer')

# ==============================================================================
# Get the bunny and construct a mesh
# ==============================================================================

bunny = Mesh.from_ply(compas.get('bunny.ply'))

# ==============================================================================
# Move the bunny to the origin and rotate it upright.
# ==============================================================================

vector = Vector(*bunny.centroid())
T = Translation.from_vector(vector.scaled(-1))
S = Scale.from_factors([100, 100, 100])
R = Rotation.from_axis_and_angle(Vector(1, 0, 0), math.radians(90))
Example #10
0
from math import radians

import compas_rhino

from compas.geometry import pointcloud
from compas.geometry import bounding_box
from compas.geometry import Rotation
from compas.geometry import Translation
from compas.geometry import Frame
from compas.geometry import Transformation
from compas.geometry import transform_points
from compas.utilities import pairwise

# from compas.numerical import pca_numpy
from compas.rpc import Proxy
numerical = Proxy('compas.numerical')

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


def draw_cloud(cloud, bbox, color, layer):
    points = [{'pos': xyz, 'color': color} for xyz in cloud]
    lines = []
    for a, b in pairwise(bbox[:4] + bbox[:1]):
        lines.append({'start': a, 'end': b, 'color': color})
    for a, b in pairwise(bbox[4:] + bbox[4:5]):
        lines.append({'start': a, 'end': b, 'color': color})
    for a, b in zip(bbox[:4], bbox[4:]):
        lines.append({'start': a, 'end': b, 'color': color})
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import os
from random import sample

from compas.datastructures import mesh_subdivide
from compas.rpc import Proxy

from compas_fofin.datastructures import Shell
from compas_fofin.rhino import ShellArtist

PROXY = Proxy('compas_fofin.fofin')

# ==============================================================================
# Initialise
# ==============================================================================

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

SHELL = Shell.from_json(FILE_I)

SHELL.update_default_face_attributes({'children': None})

# ==============================================================================
# Subdivide
# ==============================================================================
# Before running this example, you have to:
# 1) install the example library in your environment:
#    pip install -e rpc_example
# 2) (optional) start the RPC server from Anaconda Prompt
#    compas_rpc start
#
# After that, you can run this file in VS Code or in Rhino/GH
#
from compas.rpc import Proxy

proxy = Proxy('rpc_functions', python='python')
print(proxy.mean_of_random_array())
Example #13
0
from compas.geometry import subtract_vectors
from compas.geometry import add_vectors
from compas.geometry import angle_vectors
from compas.geometry import scale_vector
from compas.geometry import Vector
from compas.geometry import transform_points
from compas.geometry import Rotation

from compas_assembly.datastructures import Assembly
from compas_assembly.datastructures import Block
from compas_assembly.rhino import AssemblyArtist

from compas.rpc import Proxy

proxy = Proxy()

try:
    HERE = os.path.dirname(__file__)
except NameError:
    HERE = os.getcwd()

DATA = os.path.join(HERE, '../../../data')
FILE = os.path.join(DATA, 'arch.json')


def arch_from_rise_and_span(height, span, depth, thickness, n):
    """Create a semicircular arch from rise and span.

    Parameters
    ----------
Example #14
0
import os
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas.utilities import i_to_rgb
from compas_rhino.artists import MeshArtist
from compas.rpc import Proxy

TOL = 0.02
MAXDEV = 0.005
KMAX = 500

igl = Proxy('compas_libigl')
# igl.stop_server()
# igl.start_server()

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, '..', 'data', 'tubemesh.off')

mesh = Mesh.from_off(FILE)

V, F = mesh.to_vertices_and_faces()
V2 = igl.quadmesh_planarize((V, F), KMAX, MAXDEV)

mesh = Mesh.from_vertices_and_faces(V2, F)

dev = mesh_flatness(mesh, maxdev=TOL)

artist = MeshArtist(mesh, layer="IGL::PlanarizeQuads")
artist.clear_layer()
artist.draw_faces(color={fkey: i_to_rgb(dev[fkey]) for fkey in mesh.faces()})
import compas
import compas_rhino
import compas_tna

from compas.rpc import Proxy

from compas_tna.diagrams import FormDiagram
from compas_tna.diagrams import ForceDiagram
from compas_tna.rhino import DiagramHelper

import rhinoscriptsyntax as rs


tna = Proxy('compas_tna.equilibrium')


def horizontal(form, force, alpha=100, kmax=500):
    """Compute horizontal equilibrium by parallelising the form and force diagram.

    Parameters
    ----------
    form : compas_tna.diagrams.FormDiagram
        The form diagram.
    force : compas_tna.diagrams.ForceDiagram
        The force diagram.
    alpha : int (100)
        Weighting factor for the calculation of the target vectors.
        ``alpha = 100`` means target vectors parallel to the edges of the form diagram.
        ``alpha = 0`` means target vectors parallel to the edges of the force diagram.
    kmax : int (500)
        Maximum number of iterations.
Example #16
0
import os
import compas

from compas.rpc import Proxy
from compas_assembly.rhino import AssemblyArtist

proxy = Proxy('compas_assembly.datastructures')

FILE_I = os.path.join(os.path.dirname(__file__), 'crossvault_assembly.json')
FILE_O = os.path.join(os.path.dirname(__file__), 'crossvault_interfaces.json')

assembly = compas.json_load(FILE_I)

assembly = proxy.assembly_interfaces_numpy(assembly, tmax=0.02)

compas.json_dump(assembly, FILE_O)

artist = AssemblyArtist(assembly, layer="Crossvault::Assembly")
artist.clear_layer()

artist.draw_nodes(color={
    key: (255, 0, 0)
    for key in assembly.nodes_where({'is_support': True})
})
artist.draw_blocks()
artist.draw_edges()
artist.draw_interfaces()
Example #17
0
from compas.rpc import Proxy

graphstatics = Proxy('compas_ags.ags.graphstatics')
graphstatics.restart_server()
Example #18
0
import os
import compas_rhino
from itertools import groupby
from compas.datastructures import Mesh
from compas.datastructures import mesh_quads_to_triangles
from compas.utilities import i_to_rgb
from compas_rhino.artists import MeshArtist
from compas.rpc import Proxy

# ==============================================================================
# RPC
# ==============================================================================

igl = Proxy('compas_libigl')
igl.stop_server()
igl.start_server()

# ==============================================================================
# Input geometry
# ==============================================================================

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, '..', 'data', 'tubemesh.json')

mesh = Mesh.from_json(FILE)

tri = mesh.copy()
mesh_quads_to_triangles(tri)

# ==============================================================================
# Isolines
Example #19
0
from compas.rpc import Proxy

np = Proxy('numpy', python='python')
an_array = np.array([[1, 2], [3, 5]])
print(np.mean(an_array))
Example #20
0
from __future__ import print_function

from compas.rpc import Proxy

linalg = Proxy("scipy.linalg")

A = [[3, 2, 0], [1, -1, 0], [0, 5, 1]]
b = [2, 4, -1]

x = linalg.solve(A, b)

print(x)
from compas.geometry import add_vectors
from compas.geometry import intersection_line_plane
from compas.geometry import Frame
from compas.geometry import bounding_box
from compas.geometry import bounding_box_xy
from compas.geometry import cross_vectors
from compas.geometry import subtract_vectors
from compas.geometry import normalize_vector
from compas.geometry import scale_vector
from compas.geometry import offset_polygon
from compas.rpc import Proxy

from compas_fofin.datastructures import Shell
from compas_fofin.rhino import ShellArtist

NUMERICAL = Proxy('compas.numerical')

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


def framelines(origin, xaxis, yaxis, zaxis, name):
    lines = []

    lines.append({
        'start': origin,
        'end': add_vectors(origin, scale_vector(xaxis, 0.1)),
        'color': (255, 0, 0),
        'name': "{}.X".format(name)
    })
Example #22
0
import os
from math import pi
from random import choice
from compas.geometry import Box
from compas.geometry import Translation
from compas.geometry import Rotation
from compas.geometry import scale_vector
from compas_assembly.datastructures import Assembly
from compas_assembly.datastructures import Block
from compas_assembly.rhino import AssemblyArtist
from compas.rpc import Proxy

proxy = Proxy()

try:
    HERE = os.path.dirname(__file__)
except NameError:
    HERE = os.getcwd()

DATA = os.path.join(HERE, '../../../data')
FILE = os.path.join(DATA, 'stack.json')


def shift(block):
    """Shift a block along the X or Y axis by a randomly chosen amount.

    Parameters
    ----------
    block : compas_assembly.datastructures.Block
    """
    scale = choice([+0.05, -0.05, +0.1, -0.1])
Example #23
0
from __future__ import print_function

from compas.rpc import Proxy

proxy = Proxy()

A = [[3, 2, 0], [1, -1, 0], [0, 5, 1]]
b = [2, 4, -1]

proxy.package = "scipy.linalg"
x = proxy.solve(A, b)

print(x)
Example #24
0
import os
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas.utilities import i_to_rgb
from compas_rhino.artists import MeshArtist
from compas.rpc import Proxy

maxdev = 0.005
kmax = 500

igl = Proxy('compas_libigl')
# igl.stop_server()
# igl.start_server()

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, '..', 'data', 'tubemesh.json')

mesh = Mesh.from_json(FILE)

vertices, faces = mesh.to_vertices_and_faces()
vertices = igl.planarize_quads(vertices, faces, kmax, maxdev)

mesh = Mesh.from_vertices_and_faces(vertices, faces)

dev = mesh_flatness(mesh, maxdev=maxdev)

artist = MeshArtist(mesh, layer="IGL::PlanarizeQuads")
artist.clear_layer()
artist.draw_faces(color={fkey: i_to_rgb(dev[fkey]) for fkey in mesh.faces()})
import compas
from compas.datastructures import Mesh
from compas.rpc import Proxy
from compas_rhino.artists import MeshArtist

# create a proxy for the numerical package of COMPAS
numerical = Proxy('compas.numerical', python='pythonw')

# make a mesh from a sample OBJ file
mesh = Mesh.from_obj(compas.get('faces.obj'))

# assign default values for loads and force densities
mesh.update_default_vertex_attributes({'px': 0.0, 'py': 0.0, 'pz': 0.0})
mesh.update_default_edge_attributes({'q': 1.0})

# make a map between vertex keys (dicts)
# and vertex indices (lists, arrays)
key_index = mesh.key_index()

# convert data to a numerical format
xyz = mesh.get_vertices_attributes('xyz')
edges = [(key_index[u], key_index[v]) for u, v in mesh.edges()]
fixed = [key_index[key] for key in mesh.vertices_where({'vertex_degree': 2})]
q = mesh.get_edges_attribute('q', 1.0)
loads = mesh.get_vertices_attributes(('px', 'py', 'pz'), (0.0, 0.0, 0.0))

# run the force density algorithm
# through the proxy
xyz, q, f, l, r = numerical.fd_numpy(xyz, edges, fixed, q, loads)

# update the mesh with the result
Example #26
0
import os

from compas_assembly.datastructures import Assembly
from compas_assembly.geometry import Arch
from compas_assembly.rhino import AssemblyArtist

from compas.rpc import Proxy

proxy = Proxy()
proxy.restart_server()

try:
    HERE = os.path.dirname(__file__)
except NameError:
    HERE = os.getcwd()

DATA = os.path.join(HERE, '../../../data')
FILE = os.path.join(DATA, 'arch.json')


# ==============================================================================
# Assembly
# ==============================================================================

rise = 5
span = 10
depth = 0.5
thickness = 0.7
n = 40

arch = Arch(rise, span, thickness, depth, n)
Example #27
0
from compas.rpc import Proxy

proxy = Proxy()
Example #28
0
from compas.geometry import Box
from compas.geometry import Transformation
from compas.geometry import transform_points
from compas.geometry import cross_vectors
from compas.geometry import subtract_vectors
from compas.geometry import bounding_box_xy
from compas.geometry import offset_polygon
from compas.geometry import intersection_line_plane
import compas.geometry as cg

# ==============================================================================
# Create a proxy for PCA
# ==============================================================================

from compas.rpc import Proxy
numerical = Proxy("compas.numerical")
pca_numpy = numerical.pca_numpy

# ==============================================================================
# Construct a cablenet
# ==============================================================================

HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'data', 'cablenet.json')

cablenet = Cablenet.from_json(FILE_I)

# ==============================================================================
# Parameters
# ==============================================================================
from compas.geometry import centroid_points_xy
from compas.utilities import geometric_key
from compas.utilities import pairwise
from compas.datastructures import Mesh
from compas.rpc import Proxy

import compas_rhino
from compas_rhino.geometry import RhinoCurve
from compas_rhino.artists import MeshArtist

# ==============================================================================
# RPC
# ==============================================================================

igl = Proxy("compas_libigl")

# ==============================================================================
# Input
# ==============================================================================

# boundary
guids = compas_rhino.select_curves()
curve = RhinoCurve.from_guid(guids[0])
points = [list(point) for point in curve.points]
boundary = points

# segments
guids = compas_rhino.select_curves()
curve = RhinoCurve.from_guid(guids[0])
points = curve.divide(10, over_space=True)
segments = points
Example #30
0
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import os
from random import sample

from compas.datastructures import mesh_subdivide
from compas.geometry import add_vectors
from compas.geometry import scale_vector
from compas.rpc import Proxy

from compas_fofin.datastructures import Shell
from compas_fofin.rhino import ShellArtist

NUMERICAL = Proxy('compas.numerical')

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


def subd_tracked(mesh, k):
    levels = []
    for _ in range(k):
        mesh.update_default_face_attributes({'children': None})
        mesh.update_default_edge_attributes({'child': None})
        subd = mesh_subdivide(mesh, scheme='quad', k=1)
        subd.update_default_face_attributes({'children': None})
        subd.update_default_edge_attributes({'child': None})
        for fkey in mesh.faces():