Skip to content

Commit 64d307c

Browse files
committed
refined session data export
1 parent ffa1f85 commit 64d307c

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

commands/RV_session_export.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! python3
2+
# venv: brg-csd
3+
# r: compas_rv>=0.9.1
4+
5+
import pathlib
6+
7+
import rhinoscriptsyntax as rs # type: ignore
8+
9+
import compas
10+
from compas.datastructures import Mesh
11+
from compas_rui.forms import FileForm
12+
from compas_rv.session import RVSession
13+
14+
15+
def RunCommand():
16+
session = RVSession()
17+
18+
option = rs.GetString(
19+
message="Export",
20+
strings=[
21+
"Pattern",
22+
"FormDiagram",
23+
"ForceDiagram",
24+
"ThrustDiagram",
25+
],
26+
)
27+
28+
if option == "Pattern":
29+
pattern = session.find_pattern()
30+
if not pattern:
31+
return
32+
33+
mesh: Mesh = pattern.mesh.copy()
34+
for face in list(mesh.faces_where(_is_loaded=False)):
35+
mesh.delete_face(face)
36+
37+
basedir = session.basedir or pathlib.Path().home()
38+
basename = "Pattern.json"
39+
filepath = FileForm.save(str(basedir), basename)
40+
if not filepath:
41+
return
42+
43+
compas.json_dump(mesh, filepath)
44+
45+
elif option == "FormDiagram":
46+
form = session.find_formdiagram()
47+
if not form:
48+
return
49+
50+
mesh: Mesh = form.diagram.copy()
51+
for face in list(mesh.faces_where(_is_loaded=False)):
52+
mesh.delete_face(face)
53+
54+
basedir = session.basedir or pathlib.Path().home()
55+
basename = "FormDiagram.json"
56+
filepath = FileForm.save(str(basedir), basename)
57+
if not filepath:
58+
return
59+
60+
compas.json_dump(mesh, filepath)
61+
62+
elif option == "ForceDiagram":
63+
force = session.find_forcediagram()
64+
if not force:
65+
return
66+
67+
mesh: Mesh = force.diagram.copy()
68+
basedir = session.basedir or pathlib.Path().home()
69+
basename = "ForceDiagram.json"
70+
filepath = FileForm.save(str(basedir), basename)
71+
if not filepath:
72+
return
73+
74+
compas.json_dump(mesh, filepath)
75+
76+
elif option == "ThrustDiagram":
77+
thrust = session.find_thrustdiagram()
78+
if not thrust:
79+
return
80+
81+
mesh: Mesh = thrust.diagram.copy()
82+
for face in list(mesh.faces_where(_is_loaded=False)):
83+
mesh.delete_face(face)
84+
85+
basedir = session.basedir or pathlib.Path().home()
86+
basename = "ThrustDiagram.json"
87+
filepath = FileForm.save(str(basedir), basename)
88+
if not filepath:
89+
return
90+
91+
compas.json_dump(mesh, filepath)
92+
93+
else:
94+
raise NotImplementedError
95+
96+
97+
# =============================================================================
98+
# Run as main
99+
# =============================================================================
100+
101+
if __name__ == "__main__":
102+
RunCommand()

0 commit comments

Comments
 (0)