def open_file(settings): if not settings["file.dir"]: filepath = compas_rhino.select_file(folder=HERE, filter="fofin") else: filepath = compas_rhino.select_file(folder=settings["file.dir"], filter="fofin") if not filepath: return file_dir = os.path.dirname(filepath) file_name = os.path.basename(filepath) settings["file.dir"] = file_dir settings["file.name"] = file_name if not file_name.endswith(".fofin"): print("The filename is invalid: {}".format(file_name)) return filepath = os.path.join(file_dir, file_name) with open(filepath, "r") as f: data = json.load(f) if "settings" in data and data["settings"]: settings.update(data["settings"]) if "cablenet" in data and data["cablenet"]: cablenet = Cablenet.from_data(data["cablenet"]) cablenet.draw(layer=settings["layer"], clear_layer=True, settings=settings) else: cablenet = None return cablenet
def create_cablenet_from_lines(settings): guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) cablenet = Cablenet.from_lines(lines) return cablenet
def create_cablenet_from_json(settings): folder = settings["file.dir"] or HERE filepath = compas_rhino.select_file(folder=folder, filter="json") if not filepath: return cablenet = Cablenet.from_json(filepath) return cablenet
def cablenet_fd_rpc(data, **kwargs): """Convenience wrapper for ``cablenet_fd_numpy`` that can be used with ``RPC``. Parameters ---------- data : dict The data dictionary representing a cablenet data structure. Returns ------- dict A data dict with the same structure as the input dict. Notes ----- For additional named parameters that can be passed to this function, see ``cablenet_fd_numpy``. Examples -------- .. code-block:: python proxy = Proxy('compas_fofin.equilibrium') result = proxy.cablenet_fd_rpc(cablenet.to_data()) cablenet.data = result """ from compas_fofin.datastructures import Cablenet cablenet = Cablenet.from_data(data) cablenet_fd_numpy(cablenet) return cablenet.to_data()
def RunCommand(is_interactive): if "FoFin" not in sc.sticky: raise Exception("Initialise the plugin first!") settings = sc.sticky["FoFin"]['settings'] filepath = compas_rhino.browse_for_file() if not filepath: return if not filepath.endswith('.json'): return cablenet = Cablenet.from_json(filepath) sc.sticky["FoFin"]["cablenet"] = cablenet artist = CablenetArtist(cablenet, layer=settings['layer']) artist.clear_layer() artist.draw_mesh() artist.draw_vertices() artist.draw_edges() artist.redraw()
from compas_fofin.datastructures import Cablenet from compas_fofin.analysis import mesh_materialize_cables from compas_plotters import MeshPlotter # ============================================================================== # Create a cablenet # ============================================================================== HERE = os.path.dirname(__file__) FILE_I = os.path.join(HERE, 'hypar.json') FILE_O = os.path.join(HERE, 'hypar_materialized.json') FILE_P = os.path.join(HERE, 'hypar_materialized.png') cablenet = Cablenet.from_json(FILE_I) # ============================================================================== # Materialize # ============================================================================== mesh_materialize_cables(cablenet) # ============================================================================== # Visualize # ============================================================================== edges = list(cablenet.edges_where({'is_edge': True})) stress = [cablenet.stress(key) for key in edges] cmap = Colormap(stress, 'rgb')
import os from compas_fofin.datastructures import Cablenet from compas_fofin.rhino import CablenetArtist from compas_fofin.equilibrium import cablenet_fd_alglib HERE = os.path.dirname(__file__) DATA = os.path.join(HERE, '..', '..', 'data') FILE = os.path.join(DATA, 'saddle.obj') cablenet = Cablenet.from_obj(FILE) cablenet.set_vertices_attribute('is_anchor', True, keys=cablenet.vertices_where( {'vertex_degree': 1})) cablenet_fd_alglib(cablenet) 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()
def update_xyz_proxy(data, *args, **kwargs): from compas_fofin.datastructures import Cablenet net = Cablenet.from_data(data) update_xyz_numpy(net, *args, **kwargs) return net.to_data()
def apply_loads_proxy(data, *args, **kwargs): from compas_fofin.datastructures import Cablenet cablenet = Cablenet.from_data(data) apply_loads_numpy(cablenet, *args, **kwargs) return cablenet.to_data()
# ============================================================================== # Make a cablenet # ============================================================================== # FILE = compas.get('quadmesh.obj') # cablenet = Cablenet.from_obj(FILE) HERE = os.path.dirname(__file__) FILE_I = os.path.join(HERE, 'lines.obj') FILE_O = os.path.join(HERE, 'lines.json') obj = OBJ(FILE_I) lines = [[obj.vertices[u], obj.vertices[v]] for u, v in obj.lines] cablenet = Cablenet.from_lines(lines, delete_boundary_face=True) cablenet.edges_attribute('is_edge', False, keys=list(cablenet.edges_on_boundary())) # ============================================================================== # Select a starting edge # ============================================================================== start = random.choice( list(set(cablenet.edges()) - set(cablenet.edges_on_boundary()))) # ============================================================================== # Continuous edges and parallel edges # ==============================================================================
def create_cablenet_from_surface(settings): guid = compas_rhino.select_surface() if not guid: return cablenet = Cablenet.from_rhinosurface(guid) return cablenet
def create_cablenet_from_mesh(settings): guid = compas_rhino.select_mesh() if not guid: return cablenet = Cablenet.from_rhinomesh(guid) return cablenet
from compas_fofin.rhino import CablenetArtist from compas_fofin.rhino import CablenetHelper def draw(): artist.clear_layer() artist.draw_vertices(color={ key: (255, 0, 0) for key in cablenet.vertices_where({'is_anchor': True}) }) artist.draw_edges() artist.redraw() cablenet = Cablenet.from_obj(compas.get('faces.obj')) for key, attr in cablenet.vertices(True): attr['is_anchor'] = cablenet.vertex_degree(key) == 2 artist = CablenetArtist(cablenet, layer="Mesh::FD") draw() while True: selected = CablenetHelper.select_vertices(cablenet) if not selected: break if CablenetHelper.update_vertex_attributes(cablenet, selected): cablenet_fd(cablenet)
import os import sys from compas_fofin.datastructures import Cablenet from compas_rhino.artists import MeshArtist from compas.datastructures import Mesh from compas.geometry import add_vectors from compas.geometry import scale_vector from compas.datastructures import mesh_flip_cycles import compas.geometry as cg HERE = os.path.dirname(__file__) FILE_I = os.path.join(HERE, 'data', 'cablenet.json') FILE_O = os.path.join(HERE, 'data', 'blocks.json') cablenet = Cablenet.from_json(FILE_I) mesh_flip_cycles(cablenet) # ============================================================================== # Parameters # ============================================================================== OFFSET = 0.0500 # ============================================================================== # Make block # ============================================================================== blocks = [] all_vertices = []