Skip to content

Commit db524ef

Browse files
committed
tna
1 parent ba0c8d3 commit db524ef

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

plugin/RV_tna_horizontal.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,57 @@
77

88
from compas.geometry import Box
99
from compas.geometry import bounding_box
10-
from compas_rv.datastructures import ForceDiagram
11-
from compas_rv.datastructures import FormDiagram
12-
from compas_rv.scene import RhinoForceObject
13-
from compas_rv.scene import RhinoFormObject
1410
from compas_rv.session import RVSession
1511
from compas_tna.equilibrium import horizontal_nodal
1612

1713

1814
def RunCommand():
1915
session = RVSession()
2016

21-
formobj: RhinoFormObject = session.scene.find_by_itemtype(FormDiagram)
22-
if not formobj:
17+
form = session.find_formdiagram()
18+
if not form:
2319
return
2420

25-
forceobj: RhinoForceObject = session.scene.find_by_itemtype(ForceDiagram)
26-
if not forceobj:
21+
force = session.find_forcediagram()
22+
if not force:
2723
return
2824

2925
# =============================================================================
3026
# Compute horizontal
3127
# =============================================================================
3228

33-
kmax = session.settings.tna.horizontal.kmax
34-
alpha = session.settings.tna.horizontal.alpha
29+
kmax = session.settings.tna.horizontal_kmax
30+
alpha = session.settings.tna.horizontal_alpha
3531

36-
horizontal_nodal(formobj.mesh, forceobj.mesh, kmax=kmax, alpha=alpha)
32+
horizontal_nodal(form.diagram, force.diagram, kmax=kmax, alpha=alpha)
3733

38-
bbox_form = Box.from_bounding_box(bounding_box(formobj.mesh.vertices_attributes("xyz")))
39-
bbox_force = Box.from_bounding_box(bounding_box(forceobj.mesh.vertices_attributes("xyz")))
34+
bbox_form = Box.from_bounding_box(bounding_box(form.diagram.vertices_attributes("xyz")))
35+
bbox_force = Box.from_bounding_box(bounding_box(force.diagram.vertices_attributes("xyz")))
4036

4137
y_form = bbox_form.ymin + 0.5 * (bbox_form.ymax - bbox_form.ymin)
4238
y_force = bbox_force.ymin + 0.5 * (bbox_force.ymax - bbox_force.ymin)
4339
dx = 1.3 * (bbox_form.xmax - bbox_form.xmin) + (bbox_form.xmin - bbox_force.xmin)
4440
dy = y_form - y_force
4541

46-
forceobj.mesh.translate([dx, dy, 0])
47-
forceobj.mesh.update_angle_deviations()
42+
force.diagram.translate([dx, dy, 0])
4843

4944
# =============================================================================
5045
# Update scene
5146
# =============================================================================
5247

53-
# max_angle = max(form.diagram.edges_attribute("_a"))
54-
# tol = ui.registry["RV3"]["tol.angles"]
48+
max_angle = max(form.diagram.edges_attribute("_a"))
49+
tol_angles = session.settings.tna.horizontal_max_angle
5550

56-
# if max_angle < tol:
57-
# print("Horizontal equilibrium found!\nMaximum angle deviation: {}".format(max_angle))
58-
# else:
59-
# compas_rhino.display_message("Horizontal equilibrium NOT found! Consider running more iterations.\nMaximum angle deviation: {}".format(max_angle))
51+
if max_angle < tol_angles:
52+
print(f"Horizontal equilibrium found!\nMaximum angle deviation: {max_angle} < {tol_angles}")
53+
else:
54+
rs.MessageBox(f"Horizontal equilibrium NOT found! Consider running more iterations.\nMaximum angle deviation: {max_angle} > {tol_angles}")
6055

6156
rs.UnselectAllObjects()
6257

6358
session.scene.redraw()
6459
rs.Redraw()
6560

66-
# =============================================================================
67-
# Save session
68-
# =============================================================================
69-
7061
if session.settings.autosave:
7162
session.record(name="TNA Horizontal")
7263

plugin/RV_tna_vertical.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,69 @@
55

66
import rhinoscriptsyntax as rs # type: ignore
77

8-
from compas_rv.datastructures import FormDiagram
98
from compas_rv.datastructures import ThrustDiagram
10-
from compas_rv.scene import RhinoFormObject
11-
from compas_rv.scene import RhinoThrustObject
129
from compas_rv.session import RVSession
1310
from compas_tna.equilibrium import vertical_from_zmax
1411

1512

1613
def RunCommand():
1714
session = RVSession()
1815

19-
formobj: RhinoFormObject = session.scene.find_by_itemtype(FormDiagram)
20-
if not formobj:
16+
form = session.find_formdiagram()
17+
if not form:
18+
return
19+
20+
force = session.find_forcediagram()
21+
if not force:
22+
return
23+
24+
thrust = session.find_thrustdiagram()
25+
if not thrust:
2126
return
2227

2328
# =============================================================================
2429
# Compute horizontal
2530
# =============================================================================
2631

27-
kmax = session.settings.tna.vertical.kmax
28-
zmax = session.settings.tna.vertical.zmax
32+
# density
33+
kmax = session.settings.tna.vertical_kmax
34+
zmax = session.settings.tna.vertical_zmax
2935
zmax = rs.GetReal("Set maximum height (zmax)", number=zmax, minimum=0)
3036

31-
# warn the user about nonsensical values
37+
if zmax is None:
38+
return
39+
40+
session.settings.tna.vertical_zmax = zmax
41+
42+
# copy the vertical coordinates of the thrust diagram
43+
# onto the form diagram
44+
for vertex in thrust.diagram.vertices_where(is_support=True):
45+
z = thrust.diagram.vertex_attribute(vertex, "z")
46+
form.diagram.vertex_attribute(vertex, "z", z)
3247

33-
_, scale = vertical_from_zmax(formobj.mesh, zmax, kmax=kmax)
48+
# can we not use the thrust diagram here
49+
_, scale = vertical_from_zmax(form.diagram, zmax, kmax=kmax)
3450

3551
# store scale in force diagram
52+
print(scale)
3653

37-
thrust: ThrustDiagram = formobj.mesh.copy(cls=ThrustDiagram)
38-
thrust.name = "ThrustDiagram"
54+
thrustdiagram: ThrustDiagram = form.diagram.copy(cls=ThrustDiagram)
55+
thrustdiagram.name = "ThrustDiagram"
3956

40-
formobj.mesh.vertices_attribute(name="z", value=0)
57+
# flatten the formdiagram again
58+
form.diagram.vertices_attribute(name="z", value=0)
59+
60+
# show the thrust diagram
61+
thrust.show = True
4162

4263
# =============================================================================
4364
# Update scene
4465
# =============================================================================
4566

4667
rs.UnselectAllObjects()
4768

48-
thrustobj = session.scene.find_by_itemtype(ThrustDiagram)
49-
50-
if not thrustobj:
51-
thrustobj: RhinoThrustObject = session.scene.add(thrust, name=thrust.name)
52-
else:
53-
thrustobj.mesh = thrust
54-
55-
thrustobj.clear()
56-
thrustobj.draw()
57-
rs.Redraw()
58-
59-
# =============================================================================
60-
# Save session
61-
# =============================================================================
69+
thrust.diagram = thrustdiagram
70+
thrust.redraw()
6271

6372
if session.settings.autosave:
6473
session.record(name="TNA Vertical")

0 commit comments

Comments
 (0)