import os from compas_assembly.datastructures import Assembly from compas_assembly.rhino import AssemblyArtist try: HERE = os.path.dirname(__file__) except NameError: HERE = os.getcwd() DATA = os.path.join(HERE, '../../../data') FILE = os.path.join(DATA, 'stack.json') # ============================================================================== # Load assembly from file # ============================================================================== assembly = Assembly.from_json(FILE) # ============================================================================== # Visualize # ============================================================================== artist = AssemblyArtist(assembly, layer="Wall") artist.clear_layer() artist.draw_blocks() artist.draw_interfaces() artist.draw_resultants(scale=0.05) artist.color_interfaces(mode=1) artist.redraw()
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 # ============================================================================== artist = AssemblyArtist(assembly, layer="Armadillo") artist.clear_layer() artist.draw_nodes() artist.draw_blocks() artist.draw_edges() artist.draw_interfaces()
import os import compas from compas.rpc import Proxy from compas_assembly.rhino import AssemblyArtist proxy = Proxy('compas_rbe.equilibrium') proxy.restart_server() FILE_I = os.path.join(os.path.dirname(__file__), 'arch_interfaces.json') FILE_O = os.path.join(os.path.dirname(__file__), 'arch_equilibrium.json') assembly = compas.json_load(FILE_I) assembly = proxy.compute_interface_forces_cvx(assembly, solver='CPLEX') compas.json_dump(assembly, FILE_O) artist = AssemblyArtist(assembly, layer="Arch::Resultants") artist.clear_layer() artist.draw_nodes(color={ key: (255, 0, 0) for key in assembly.nodes_where({'is_support': True}) }) artist.draw_edges() artist.draw_blocks() artist.draw_interfaces() artist.draw_resultants(scale=0.1)
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()
# just so Rhino(Mac) gets the filepaths right HERE = os.path.dirname(__file__) # load an assembly from a JSON file assembly = Assembly.from_json(os.path.join(HERE, '../data/wall_courses.json')) # make a list of the blocks that were already placed placed = list(assembly.vertices_where({'is_placed': True})) # draw the assembly artist = AssemblyArtist(assembly, layer="Assembly") artist.clear_layer() artist.draw_vertices() artist.draw_blocks(show_faces=False, show_edges=True) # draw filled in blocks for the placed ones if placed: artist.draw_blocks(keys=placed, show_faces=True, show_edges=False) # make sure Rhino redraws the view artist.redraw() # select a block
def draw(self, settings=None): """Convenience function for drawing the assembly in Rhino using common visualisation settings. Parameters ---------- settings : dict, optional A dictionary with drawing options. In addition to all configuration options supported by the ``AssemblyArtist``, the following options are supported: * layer: The layer in which the assembly should be drawn. If provided, the layer will be cleared. * show.vertices: ``True``/``False``. * show.edges: ``True``/``False``. * show.faces: ``True``/``False``. * show.forces: ``True``/``False``. * show.forces_as_vectors: ``True``/``False``. * show.interfaces: ``True``/``False``. * show.friction: ``True``/``False``. * show.selfweight: ``True``/``False``. Notes ----- This function is provided for convenience. For more drawing options, see the ``AssemblyArtist``. """ from compas_assembly.rhino import AssemblyArtist settings = settings or {} artist = AssemblyArtist(self, layer=settings.get('layer')) artist.defaults.update(settings) artist.clear_layer() artist.draw_blocks() vertexcolor = { key: artist.defaults['color.vertex:is_support'] for key in self.vertices_where({'is_support': True}) } if settings.get('show.vertices'): artist.draw_vertices(color=vertexcolor) if settings.get('show.edges'): artist.draw_edges() if settings.get('show.interfaces'): artist.draw_interfaces() if settings.get('show.forces'): if settings.get('mode.interface') == 0: artist.color_interfaces(0) else: artist.color_interfaces(1) if settings.get('show.forces_as_vectors'): if settings.get('mode.force') == 0: artist.draw_forces(mode=0) else: artist.draw_forces(mode=1) if settings.get('show.selfweight'): artist.draw_selfweight() if settings.get('show.frictions'): if settings.get('mode.friction') == 0: artist.draw_frictions(mode=0) else: artist.draw_frictions(mode=1) artist.redraw()
{str(key): assembly.blocks[key].to_data() for key in assembly.blocks} } data = proxy.compute_interface_forces_xfunc(data, backend='CVX', solver='CPLEX') assembly.data = data['assembly'] assembly.blocks = { int(key): Block.from_data(data['blocks'][key]) for key in data['blocks'] } # ============================================================================== # Visualize # ============================================================================== artist = AssemblyArtist(assembly, layer="Arch") artist.clear_layer() artist.draw_blocks() # artist.draw_edges() artist.draw_nodes(color={ key: (255, 0, 0) for key in assembly.nodes_where({'is_support': True}) }) artist.draw_interfaces() artist.draw_resultants() artist.color_interfaces(mode=1) artist.redraw()
import os from compas_assembly.datastructures import Assembly from compas_assembly.rhino import AssemblyArtist try: HERE = os.path.dirname(__file__) except NameError: HERE = os.getcwd() DATA = os.path.join(HERE, '../../../data') FILE = os.path.join(DATA, 'stack.json') # ============================================================================== # Load assembly from file # ============================================================================== assembly = Assembly.from_json(FILE) # ============================================================================== # Visualize # ============================================================================== artist = AssemblyArtist(assembly, layer="Wall") artist.clear_layer() artist.draw_nodes() artist.draw_edges() artist.draw_blocks() artist.draw_interfaces() artist.draw_forces() artist.redraw()
import os import compas from compas_assembly.datastructures import Assembly from compas_assembly.datastructures import Block from compas_assembly.rhino import AssemblyArtist FILE_I = os.path.join(os.path.dirname(__file__), 'crossvault_meshes.json') FILE_O = os.path.join(os.path.dirname(__file__), 'crossvault_assembly.json') meshes = compas.json_load(FILE_I) assembly = Assembly() for mesh in meshes: block = mesh.copy(cls=Block) assembly.add_block(block) 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()