Exemple #1
0
    def from_json(cls, filepath):
        """Construct an object from serialized data contained in a JSON file.

        Parameters
        ----------
        filepath : path string, file-like object or URL string
            The path, file or URL to the file for serialization.

        Returns
        -------
        :class:`compas.data.Data`
            An object of the type of ``cls``.
        """
        data = compas.json_load(filepath)
        return cls.from_data(data)
import compas

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

from compas.rpc import Proxy

# prepare proxy for RPC

proxy = Proxy('compas_assembly.datastructures')

# load meshes

FILE = os.path.join(os.path.dirname(__file__), 'armadillo.json')
meshes = compas.json_load(FILE)

# construct assembly

assembly = Assembly()
for mesh in meshes:
    block = mesh.copy(cls=Block)
    assembly.add_block(block)

# identify interfaces

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

# ==============================================================================
# Visualization
# ==============================================================================
Exemple #3
0
 def from_json(cls, filepath):
     data = compas.json_load(filepath)
     return cls.from_data(data)
Exemple #4
0
def test_json_url():
    data = compas.json_load(
        'https://raw.githubusercontent.com/compas-dev/compas/main/schemas/graph.json'
    )
    assert data['$schema'] == 'http://json-schema.org/draft-07/schema#'
Exemple #5
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__), 'armadillo_assembly.json')
FILE_O = os.path.join(os.path.dirname(__file__), 'armadillo_interfaces.json')

assembly = compas.json_load(FILE_I)

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

compas.json_dump(assembly, FILE_O)

artist = AssemblyArtist(assembly, layer="Armadillo::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()
import compas

from openpyxl import Workbook
from openpyxl import utils
from openpyxl.styles import Font

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '../data')
FILE_I = os.path.join(DATA, 'session.json')
FILE_O = os.path.join(DATA, 'cables.xlsx')

# ==============================================================================
# Data
# ==============================================================================

session = compas.json_load(FILE_I)

mesh = session['mesh']
export = session['export']

cap08 = 0
cap10 = 0

# ==============================================================================
# Workbook
# ==============================================================================

headerfont = Font(bold=True, color="ff0000")

wb = Workbook()
ws = wb.active
Exemple #7
0
def test_from_lines():
    lines = compas.json_load(compas.get('lines.json'))
    mesh = Mesh.from_lines(lines)
    assert mesh.number_of_faces() == 10
    assert mesh.number_of_vertices() == 32
    assert mesh.number_of_edges() == 40
Exemple #8
0
 def RunScript(self, json):
     try:
         return compas.json_load(json)
     except:  # noqa: E722
         return compas.json_loads(json)