Skip to content

Commit f2bc00d

Browse files
committed
eto compatible edgemodifier
1 parent c0f4daf commit f2bc00d

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/compas/datastructures/_mixins/fromto.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def from_json(cls, filepath):
9292
graph.data = data
9393
return graph
9494

95-
def to_json(self, filepath):
95+
def to_json(self, filepath, pretty=False):
9696
"""Serialise the structured data representing the data structure to json.
9797
9898
Parameters
@@ -102,7 +102,10 @@ def to_json(self, filepath):
102102
103103
"""
104104
with open(filepath, 'w+') as fp:
105-
json.dump(self.data, fp)
105+
if pretty:
106+
json.dump(self.data, fp, sort_keys=True, indent=4)
107+
else:
108+
json.dump(self.data, fp)
106109

107110

108111
class FromToPickle(object):

src/compas_rhino/modifiers/edgemodifier.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,41 @@
1414
except ImportError:
1515
compas.raise_if_ironpython()
1616

17+
try:
18+
from compas_rhino.etoforms import PropertyListForm
19+
20+
except:
21+
try:
22+
from Rhino.UI.Dialogs import ShowPropertyListBox
23+
24+
except ImportError:
25+
compas.raise_if_ironpython()
26+
else:
27+
try:
28+
import clr
29+
clr.AddReference('Rhino.UI')
30+
import Rhino.UI
31+
32+
except ImportError:
33+
compas.raise_if_ironpython()
34+
1735

1836
__all__ = ['EdgeModifier']
1937

2038

39+
def rhino_update_named_values(names, values, message='', title='Update named values'):
40+
try:
41+
dialog = PropertyListForm(names, values)
42+
except:
43+
values = ShowPropertyListBox(message, title, names, values)
44+
else:
45+
if dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow):
46+
values = dialog.values
47+
else:
48+
values = None
49+
return values
50+
51+
2152
class EdgeModifier(object):
2253

2354
@staticmethod
@@ -39,10 +70,8 @@ def update_edge_attributes(self, keys, names=None):
3970
if values[i] != self.get_edge_attribute(key, name):
4071
values[i] = '-'
4172
break
42-
4373
values = map(str, values)
44-
values = compas_rhino.update_named_values(names, values)
45-
74+
values = rhino_update_named_values(names, values)
4675
if values:
4776
for name, value in zip(names, values):
4877
if value != '-':

0 commit comments

Comments
 (0)