def horizontal_nodal_xfunc(formdata, forcedata, *args, **kwargs): from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = ForceDiagram.from_formdiagram(form) del TNA['force'] TNA['force'] = force force.draw(layer=TNA['settings']['layer.force'], clear_layer=True)
def from_vertices_and_faces(vs, fs): mesh = Mesh.from_vertices_and_faces(vs, fs) form = FormDiagram.from_mesh(mesh) corners = list(form.vertices_where({'vertex_degree': 2})) form.vertices_attribute('is_anchor', True, keys=corners) form.edges_attribute('q', 10.0, keys=form.edges_on_boundary()) relax_boundary_openings(form, corners) form.update_boundaries() force = ForceDiagram.from_formdiagram(form) horizontal_nodal(form, force, alpha=95) scale = vertical_from_zmax(form, 450.0) return form
# Note: you should apply 3 sets of constraints # 1. the edges in the spanning direction => fmin := 2, fmax := 2 # 2. the edges in the spanning direction on the boundary => fmin := 1, fmin := 1 # 3. the edges in the opposite direction => fmin := 0, fmax := 0 while True: edges = DiagramHelper.select_edges(form) if not edges: break if DiagramHelper.update_edge_attributes(form, edges): form.draw(layer='TNA::FormDiagram', clear_layer=True) # 5. make the force diagram force = ForceDiagram.from_formdiagram(form) force.draw(layer='TNA::ForceDiagram', clear_layer=True) DiagramHelper.move(force) force.draw(layer='TNA::ForceDiagram', clear_layer=True) # 6. compute horizontal equilibrium horizontal(form, force, alpha=100, kmax=500) force.draw(layer='TNA::ForceDiagram', clear_layer=True) # 7. compute vertical equilibrium based on a chosen height of the highest point of the equilibrium network while True: zmax = rs.GetReal('Z Max')
import compas import compas_rhino import compas_tna compas_tna.TEMP = os.path.join(os.path.dirname(__file__), 'tmp') from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist # create diagrams from serialised files form = FormDiagram.from_json('aag_08_final_formdiagram.json') force = ForceDiagram.from_json('aag_08_final_forcediagram.json') # draw the result form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') artist = FormArtist(form, layer='AAG::FormDiagram') artist.clear_reactions() artist.draw_reactions(scale=0.25) artist.draw_forces(scale=0.01) artist.redraw()
def horizontal_nodal_proxy(formdata, forcedata, *args, **kwargs): form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
def __init__(self): ForceDiagram.__init__(self)
import compas_tna from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal # create diagrams from serialised files form = FormDiagram.from_json('aag_02_formdiagram.json') force = ForceDiagram.from_json('aag_03_forcediagram.json') # draw the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') # compute horizontal equilibrium # form.set_edges_attribute('lmin', 0.2) form.set_edges_attribute('fmin', 0.2) form.set_edges_attribute('fmax', 5.0) horizontal(form, force, alpha=100, kmax=1000) # draw the diagrams
import compas_tna from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files form = FormDiagram.from_json('aag_04_horizontal_formdiagram.json') force = ForceDiagram.from_json('aag_04_horizontal_forcediagram.json') # compute the scale of the force diagram # such that the highest vertex of the form diagram is at a prescribed value zmax = 3 scale = vertical(form, zmax, kmax=100) force.attributes['scale'] = scale print(scale) # draw the result form.draw(layer='AAG::FormDiagram')
from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files form = FormDiagram.from_json('aag_06_distribution_formdiagram.json') force = ForceDiagram.from_json('aag_06_distribution_forcediagram.json') # visualise the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') # update the force bounds on the edges of the form diagram while True: keys = DiagramHelper.select_continuous_edges(form) if not keys: break DiagramHelper.update_edge_attributes(form, keys) # update the horizontal equilibrium
from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files <<<<<<< HEAD form = FormDiagram.from_json('aag_07_formdiagram_tweaked.json') force = ForceDiagram.from_json('aag_07_forcediagram_tweaked.json') ======= form = FormDiagram.from_json('aag_06_distribution_formdiagram.json') force = ForceDiagram.from_json('aag_06_distribution_forcediagram.json') >>>>>>> eedc4909fa94efc94d3da187e62f355a854c5508 # visualise the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') ## update the force bounds on the edges of the form diagram # #while True:
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = TNA['force'] settings = TNA['settings'] options = ['save', 'save_as', 'open'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'save': # save the current file in the current directory # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return settings['file.dir'] = file_dir if not settings['file.name']: file_name = compas_rhino.select_file(folder=settings['file.dir']) if not file_name: print('The filename is invalid: {}'.format(file_name)) return settings['file.name'] = file_name file_name = settings['file.name'] if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) # compile the data dict data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() # write the data dict to the specified file with open(filepath, 'w') as f: json.dump(data, f) elif option == 'save_as': # save the current file using a different name and location # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) settings['file.dir'] = file_dir if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return file_name = rs.GetString('File name') if not file_name: print('The filename is invalid: {}'.format(file_name)) return if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return settings['file.dir'] = file_dir settings['file.name'] = file_name if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'open': # open a specified file # and update the current file properties in the settings # get the dirname of the current filepath if not settings['file.dir']: filepath = compas_rhino.select_file( folder=HERE, filter='JSON files (*.json)|*.json||') else: filepath = compas_rhino.select_file( folder=settings['file.dir'], filter='JSON files (*.json)|*.json||') 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('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) compas_rhino.clear_layer(settings['layer.form']) compas_rhino.clear_layer(settings['layer.force']) with open(filepath, 'r') as f: data = json.load(f) settings.update(data['settings']) if 'form' in data and data['form']: form = FormDiagram.from_data(data['form']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings) else: form = None if form and 'force' in data and data['force']: force = ForceDiagram.from_data(data['force']) force.draw(layer=settings['layer.force'], clear_layer=True) else: force = None del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = force TNA['settings'] = settings else: # any other options are invalid raise NotImplementedError
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = TNA['force'] settings = TNA['settings'] options = ['save', 'save as', 'open'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'save': if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=compas_tna.DATA) else: file_dir = settings['file.dir'] if not os.path.isdir(file_dir): return if not settings['file.name']: file_name = rs.GetString('File name') if not file_name: return else: file_name = settings['file.name'] if not file_name.endswith('.json'): file_name += '.json' filepath = os.path.join(file_dir, file_name) if not filepath: return data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'save as': file_dir = compas_rhino.select_folder(default=compas_tna.DATA) if not file_dir: return if not os.path.isdir(file_dir): return file_name = rs.GetString('File name') if not file_name: return if not file_name.endswith('.json'): file_name += '.json' settings['file.dir'] = file_dir settings['file.name'] = file_name filepath = os.path.join(file_dir, file_name) if not filepath: return data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'open': filepath = compas_rhino.select_file(folder=settings['file.dir'], filter='json') if not filepath: return compas_rhino.clear_layer(settings['layer.form']) compas_rhino.clear_layer(settings['layer.force']) with open(filepath, 'r') as f: data = json.load(f) settings.update(data['settings']) if 'form' in data: if data['form']: form = FormDiagram.from_data(data['form']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings) else: form = None else: form = None if form: if 'force' in data: if data['force']: force = ForceDiagram.from_data(data['force']) force.draw(layer=settings['layer.force'], clear_layer=True) else: force = None else: force = None del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = force TNA['settings'] = settings else: raise NotImplementedError
from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files form = FormDiagram.from_json('aag_05_vertical_formdiagram.json') force = ForceDiagram.from_json('aag_05_vertical_forcediagram.json') # visualise the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') # update the force bounds on the edges of the form diagram while True: keys = DiagramHelper.select_continuous_edges(form) if not keys: break DiagramHelper.update_edge_attributes(form, keys) # update the horizontal equilibrium