5
5
import logging
6
6
import json
7
7
import pickle
8
+ import tempfile
9
+ import uuid
8
10
9
11
from honeybee .model import Model
10
12
from honeybee .cli import main
@@ -116,8 +118,7 @@ def display():
116
118
'file and the distinction between the two is only for help in coordinating file '
117
119
'extensions (since both .vsf and .json can be acceptable). Also note that '
118
120
'ladybug-vtk must be installed in order for the vtkjs or html options to be usable '
119
- 'and the html format refers to a web page with the vtkjs file embedded within it. '
120
- 'The vtkjs and html options also require an explicit --output-file to be specified.' ,
121
+ 'and the html format refers to a web page with the vtkjs file embedded within it.' ,
121
122
type = str , default = 'vsf' , show_default = True )
122
123
@click .option (
123
124
'--output-file' , help = 'Optional file to output the JSON string of '
@@ -170,14 +171,16 @@ def model_to_vis_set(
170
171
else :
171
172
output_file .write (pickle .dumps (vis_set .to_dict ()))
172
173
elif output_format in ('vtkjs' , 'html' ):
173
- assert output_file .name != '<stdout>' , \
174
- 'Must specify an --output-file to use --output-format vtkjs.'
175
- out_folder , out_file = os .path .split (output_file .name )
176
- try :
174
+ if output_file .name == '<stdout>' : # get a temporary file
175
+ out_file = str (uuid .uuid4 ())[:6 ]
176
+ out_folder = tempfile .gettempdir ()
177
+ else :
178
+ out_folder , out_file = os .path .split (output_file .name )
177
179
if out_file .endswith ('.vtkjs' ):
178
180
out_file = out_file [:- 6 ]
179
181
elif out_file .endswith ('.html' ):
180
182
out_file = out_file [:- 5 ]
183
+ try :
181
184
if output_format == 'vtkjs' :
182
185
vis_set .to_vtkjs (output_folder = out_folder , file_name = out_file )
183
186
if output_format == 'html' :
@@ -186,6 +189,16 @@ def model_to_vis_set(
186
189
raise AttributeError (
187
190
'Ladybug-vtk must be installed in order to use --output-format '
188
191
'vtkjs.\n {}' .format (ae ))
192
+ if output_file .name == '<stdout>' : # load file contents to stdout
193
+ out_file_ext = out_file + '.' + output_format
194
+ out_file_path = os .path .join (out_folder , out_file_ext )
195
+ if output_format == 'html' :
196
+ with open (out_file_path , encoding = 'utf-8' ) as of :
197
+ f_contents = of .read ()
198
+ else : # vtkjs can only be read as binary
199
+ with open (out_file_path , 'rb' ) as of :
200
+ f_contents = of .read ()
201
+ output_file .write (f_contents )
189
202
else :
190
203
raise ValueError ('Unrecognized output-format "{}".' .format (output_format ))
191
204
except Exception as e :
0 commit comments