Skip to content

Commit c9e2248

Browse files
committed
simplified export
1 parent 7d3c136 commit c9e2248

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

commands/FF_session_export.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# venv: brg-csd
33
# r: compas_fofin>=0.15.2
44

5-
import rhinoscriptsyntax as rs # type: ignore
5+
import pathlib
66

7+
# import rhinoscriptsyntax as rs # type: ignore
78
import compas
9+
from compas.datastructures import Mesh
810
from compas_fofin.scene import RhinoCableMeshObject
911
from compas_fofin.session import FoFinSession
1012
from compas_rui.forms import FileForm
@@ -13,26 +15,35 @@
1315
def RunCommand():
1416
session = FoFinSession()
1517

16-
meshobj: RhinoCableMeshObject = session.scene.find_by_name(name="CableMesh")
17-
18-
options = ["Scene", "CableMesh"]
19-
option = rs.GetString(message="Export", strings=options)
20-
if not option:
18+
meshobj: RhinoCableMeshObject = session.find_cablemesh()
19+
if not meshobj:
2120
return
2221

23-
if option == "Scene":
24-
filepath = FileForm.save(session.basedir, "FormFinder-scene.json")
25-
if not filepath:
26-
return
22+
# options = ["Scene", "CableMesh"]
23+
# option = rs.GetString(message="Export", strings=options)
24+
# if not option:
25+
# return
26+
27+
# if option == "Scene":
28+
# filepath = FileForm.save(session.basedir, "FormFinder-Scene.json")
29+
# if not filepath:
30+
# return
31+
32+
# compas.json_dump(session.scene, filepath)
2733

28-
compas.json_dump(session.scene, filepath)
34+
# elif option == "CableMesh":
2935

30-
elif option == "CableMesh":
31-
filepath = FileForm.save(session.basedir, "FormFinder-cablemesh.json")
32-
if not filepath:
33-
return
36+
mesh: Mesh = meshobj.mesh.copy()
37+
for face in list(mesh.faces_where(_is_loaded=False)):
38+
mesh.delete_face(face)
39+
40+
basedir = session.basedir or pathlib.Path().home()
41+
basename = "FormFinder-Cablemesh.json"
42+
filepath = FileForm.save(str(basedir), basename)
43+
if not filepath:
44+
return
3445

35-
compas.json_dump(meshobj.mesh, filepath)
46+
compas.json_dump(mesh, filepath)
3647

3748

3849
# =============================================================================

src/compas_fofin/session.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ def __init__(self, **kwargs):
2020
def clear(self, clear_scene=True, clear_context=True):
2121
for sceneobject in self.scene.objects:
2222
if hasattr(sceneobject, "clear_conduits"):
23-
sceneobject.clear_conduits()
23+
sceneobject.clear_conduits() # type: ignore
2424
self.scene.clear(clear_scene=clear_scene, clear_context=clear_context)
2525

2626
def clear_conduits(self):
2727
for sceneobject in self.scene.objects:
2828
if hasattr(sceneobject, "clear_conduits"):
29-
sceneobject.clear_conduits()
29+
sceneobject.clear_conduits() # type: ignore
3030

3131
def confirm(self, message):
3232
result = rs.MessageBox(message, buttons=4 | 32 | 256 | 0, title="Confirmation")
3333
return result == 6
3434

3535
def warn(self, message):
3636
return rs.MessageBox(message, title="Warning")
37+
38+
def find_cablemesh(self, warn=True):
39+
from compas_fofin.datastructures import CableMesh
40+
from compas_fofin.scene import RhinoCableMeshObject
41+
42+
cablemesh: RhinoCableMeshObject = self.scene.find_by_itemtype(CableMesh) # type: ignore
43+
if cablemesh:
44+
return cablemesh
45+
if warn:
46+
rs.MessageBox("There is no CableMesh.", title="Warning")

0 commit comments

Comments
 (0)