Exemple #1
0
def RunCommand(is_interactive):
    if 'TNA' not in sc.sticky:
        raise Exception("Initialise the plugin first!")

    TNA = sc.sticky['TNA']

    settings = TNA['settings']

    options = ['obj', 'json', 'lines', 'mesh']
    option = rs.GetString("Initialise FormDiagram from", options[0], options)
    if not option:
        return

    if option == 'obj':
        filepath = compas_rhino.select_file(folder=compas_tna.DATA,
                                            filter='OBJ files (*.obj)|*.obj||')
        if not filepath:
            return
        form = FormDiagram.from_obj(filepath)
    elif option == 'json':
        filepath = compas_rhino.select_file(
            folder=compas_tna.DATA, filter='JSON files (*.json)|*.json||')
        if not filepath:
            return
        form = FormDiagram.from_json(filepath)
    elif option == 'lines':
        guids = compas_rhino.select_lines()
        if not guids:
            return
        lines = compas_rhino.get_line_coordinates(guids)
        form = FormDiagram.from_lines(lines)
    elif option == 'mesh':
        guid = compas_rhino.select_mesh()
        if not guid:
            return
        form = FormDiagram.from_rhinomesh(guid)
    else:
        raise NotImplementedError

    del TNA['form']
    del TNA['force']

    TNA['form'] = form
    TNA['force'] = None

    compas_rhino.clear_layer(settings['layer.force'])
    form.draw(layer=settings['layer.form'],
              clear_layer=True,
              settings=settings)
Exemple #2
0
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()
import compas_tna

from compas_tna.diagrams import FormDiagram
from compas_tna.diagrams import ForceDiagram
from compas_tna.equilibrium import horizontal_nodal
from compas_plotters import MeshPlotter

FILE = compas_tna.get('tutorial/boundaryconditions.json')

form = FormDiagram.from_json(FILE)
force = ForceDiagram.from_formdiagram(form)

horizontal_nodal(form, force, kmax=100)

# ==============================================================================
# Visualise
# ==============================================================================

plotter = MeshPlotter(force, figsize=(12, 8), tight=True)

vertexcolor = {
    key: (1.0, 0.9, 0.9)
    for key in force.vertices() if not form.face_attribute(key, '_is_loaded')
}

radius = {key: 0.05 for key in force.vertices()}
radius.update({
    key: 0.1
    for key in force.vertices() if not form.face_attribute(key, '_is_loaded')
})
Exemple #4
0
from __future__ import print_function

import compas
import compas_rhino
import compas_tna

from compas_tna.diagrams import FormDiagram
from compas_tna.diagrams import ForceDiagram

from compas_tna.rhino import DiagramHelper


# create a form diagram from a serialised file

form = FormDiagram.from_json('aag_02_formdiagram.json')


# create a force diagram from the form diagram

force = ForceDiagram.from_formdiagram(form)


# visualise the result

force.draw(layer='AAG::ForceDiagram')


# move the force diagram to a different location

DiagramHelper.move(force)
Exemple #5
0
import compas_rhino
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
Exemple #6
0
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
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)
from compas_tna.diagrams import FormDiagram
from compas_tna.diagrams import ForceDiagram

from compas.plotters import MeshPlotter


form = FormDiagram.from_json('data/boundaryconditions.json')
force  = ForceDiagram.from_formdiagram(form)

# ==============================================================================
# Visualise
# ==============================================================================

plotter = MeshPlotter(force, figsize=(12, 8), tight=True)

vertexcolor = {key: (1.0, 0.9, 0.9) for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')}

radius = {key: 0.05 for key in force.vertices()}
radius.update({key: 0.1 for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')})

plotter.draw_vertices(facecolor=vertexcolor, radius=radius)

color = {key: '#00ff00' for key in force.edges() if force.get_form_edge_attribute(form, key, 'is_external')}
width = {key: 2.0 for key in force.edges() if force.get_form_edge_attribute(form, key, 'is_external')}

plotter.draw_edges(color=color, width=width)

plotter.show()
Exemple #8
0
    viewer = VtkViewer(datastructure=form)
    viewer.setup()
    viewer.start()


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    # Load FormDiagram

    file = '/home/al/compas_loadpath/data/gridshell.json'
    form = FormDiagram.from_json(file)

    # Single run

    # form = randomise_form(form)
    # fopt, qopt = optimise_single(form, qmax=5, population=200, generations=200, printout=10, tol=0.01)

    # Multiple runs

    fopts, forms, best = optimise_multi(form,
                                        trials=50,
                                        save_figs='/home/al/temp/lp/',
                                        qmin=-5,
                                        qmax=5,
                                        population=200,
                                        generations=200,
Exemple #9
0
from __future__ import print_function

import compas
import compas_rhino
import compas_tna

from compas.geometry import mesh_smooth_area

from compas_tna.diagrams import FormDiagram

# create a form diagram from a serialised file

form = FormDiagram.from_json('aag_01_formdiagram_from_mesh.json')

# smooth the diagram keeping some of the vertices fixed

fixed = list(form.vertices_where({'is_anchor': True}))
fixed += list(form.vertices_where({'is_fixed': True}))
fixed += [
    key for fkey in form.faces_where({'is_loaded': False})
    for key in form.face_vertices(fkey)
]

fixed[:] = list(set(fixed))

mesh_smooth_area(form, fixed=fixed, kmax=50)

# serialise the result

form.to_json('aag_02_formdiagram.json')
Exemple #10
0
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

<<<<<<< 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
#
""""""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import compas_tna

from compas_tna.diagrams import FormDiagram
from compas_tna.diagrams import ForceDiagram
from compas_tna.equilibrium import horizontal

from compas.plotters import MeshPlotter

form = FormDiagram.from_json(compas_tna.get('form_boundaryconditions.json'))
force  = ForceDiagram.from_formdiagram(form)

horizontal(form, force)

# force.plot()

plotter = MeshPlotter(force, figsize=(12, 8), tight=True)

vertexcolor = {key: (1.0, 0.9, 0.9) for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')}

radius = {key: 0.05 for key in force.vertices()}
radius.update({key: 0.1 for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')})

plotter.draw_vertices(
	facecolor=vertexcolor,
	radius=radius
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
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)