Skip to content

Commit 639238f

Browse files
committed
add loads command
1 parent 47279cd commit 639238f

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

commands/TNA_loads.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#! python3
2+
# venv: brg-csd
3+
# r: compas_masonry
4+
5+
import rhinoscriptsyntax as rs # type: ignore
6+
7+
from compas_masonry.scene import RhinoFormDiagramObject
8+
from compas_masonry.session import MasonrySession as Session
9+
from compas_rui import feedback
10+
from compas_tna.diagrams import FormDiagram
11+
from compas_tna.envelope import Envelope
12+
13+
14+
def RunCommand():
15+
session = Session()
16+
17+
formdiagram: FormDiagram = session["formdiagram"]
18+
19+
if not formdiagram:
20+
feedback.warn("There is no FormDiagram. Please create one first.")
21+
return
22+
23+
formobject: RhinoFormDiagramObject = session.scene.find_by_itemtype(FormDiagram) # type: ignore
24+
if not formobject:
25+
session.scene.add(formdiagram, name="FormDiagram", layer="Masonry::TNA::FormDiagram") # type: ignore
26+
27+
envelope: Envelope = session["envelope"]
28+
if not envelope:
29+
feedback.warn("There is no Envelope. Please create one first.")
30+
return
31+
32+
# =============================================================================
33+
# Update the supports
34+
# =============================================================================
35+
36+
rs.UnselectAllObjects()
37+
38+
options = ["Add", "Remove"]
39+
option = rs.GetString("Add or Remove supports", strings=options)
40+
if not option:
41+
return
42+
43+
if option == "Add":
44+
option = rs.GetString("Type of load", strings=["Selfweight", "External"])
45+
if not option:
46+
return
47+
48+
if option == "Selfweight":
49+
envelope.apply_selfweight_to_formdiagram(formdiagram)
50+
51+
elif option == "External":
52+
formobject.show_vertices = list(formobject.vertices()) # type: ignore
53+
formobject.show_edges = list(formobject.edges()) # type: ignore
54+
formobject.redraw()
55+
56+
selected = formobject.select_vertices()
57+
if selected:
58+
load = rs.GetReal("Load magnitude", -1.0, -1000.0, 0.0)
59+
if load is None:
60+
return
61+
62+
for key in selected:
63+
pz = formdiagram.vertex_attribute(key, "pz") or 0
64+
formdiagram.vertex_attribute(key, "pz", pz + load)
65+
66+
elif option == "Remove":
67+
formobject.mesh.vertices_attribute(name="pz", value=0)
68+
69+
else:
70+
raise NotImplementedError
71+
72+
# =============================================================================
73+
# Update scene
74+
# =============================================================================
75+
76+
rs.UnselectAllObjects()
77+
78+
formobject.show_edges = True # type: ignore
79+
formobject.show_faces = False # type: ignore
80+
formobject.redraw()
81+
82+
rs.Redraw()
83+
84+
# =============================================================================
85+
# Save
86+
# =============================================================================
87+
88+
# if session.settings.autosave:
89+
# session.record(name="Analysis")
90+
91+
92+
# =============================================================================
93+
# Run as main
94+
# =============================================================================
95+
96+
if __name__ == "__main__":
97+
RunCommand()

0 commit comments

Comments
 (0)