Search…
Visualize Results in Rhino
In this section, we downloaded the "visualization" output of a daylight-factor study in the web app. Now, we will see how we can download the "result" output and visualize it in Rhino.

Data needed for this visualization

Using the steps mentioned here, download the "results" output of the daylight-factor study instead of the "visualization" output.
This should give you a results folder with the following structure:
1
results
2
│ grids_info.json
3
4
├───room_1
5
│ TestRoom_1.res
6
7
└───room_2
8
TestRoom_2.res
Copied!
We will also need the original HBJSON file used for the daylight-factor study in this step.

App

Installing necessary libraries
1
pip install pollination-streamlit-io lbt-honeybee
Copied!
importing libraries
1
import json
2
import streamlit as st
3
from typing import List
4
from pathlib import Path
5
from honeybee.model import Model as HBModel
6
from pollination_streamlit_io import button, inputs, special
Copied!
Helper function to send a Honeybee model to Rhino
1
def rhino_hbjson(hb_model: HBModel, label: str = 'Preview model',
2
key: str = 'model') -> None:
3
"""Visualize and bake HBJSON in rhino.
4
5
args:
6
hb_model: A honeybee model.
7
label: Label of the button. Defaults to 'Preview model'.
8
key: Key of the button. Defaults to 'model'.
9
"""
10
11
if not st.session_state.host == 'rhino':
12
return
13
14
col1, col2 = st.columns(2)
15
16
with col1:
17
inputs.send(
18
data=hb_model.to_dict(),
19
unique_id='preview-model',
20
default_checked=True,
21
is_pollination_model=True,
22
label=label,
23
key=key,
24
)
25
26
with col2:
27
button.send(
28
action='BakePollinationModel',
29
data=hb_model.to_dict(),
30
unique_id='bake-model',
31
options={
32
"layer": "hbjson",
33
"units": "Meters"
34
},
35
key=f'bake-{key}',
36
)
Copied!
Helper function to send results as a colored mesh in Rhino
1
def rhino_mesh(hb_model: HBModel, results_folder: Path, result_name: str) -> None:
2
"""Visualize and bake the mesh in Rhino
3
4
Args:
5
hb_model: A honeybee model.
6
results_folder: Path to the folder where the results are stored.
7
result_name: The name of the result to be loaded as mesh.
8
"""
9
10
if not st.session_state.host == 'rhino':
11
return
12
13
grids_info_file = results_folder.joinpath('grids_info.json')
14
info = json.loads(grids_info_file.read_text())
15
model = hb_model.to_dict()
16
17
grids = model['properties']['radiance']['sensor_grids']
18
19
geometries = []
20
merged_values = []
21
for i, grid_info in enumerate(info):
22
result_file = results_folder.joinpath(f"{grid_info['full_id']}.res")
23
values = [float(v) for v in result_file.read_text().splitlines()]
24
mesh = json.dumps(grids[i]['mesh'])
25
merged_values += values
26
geometries.append(json.loads(mesh))
27
28
result_json = {
29
"type": "AnalyticalMesh",
30
"mesh": geometries,
31
"values": merged_values
32
}
33
34
col1, col2 = st.columns(2)
35
36
with col1:
37
inputs.send(
38
data=result_json,
39
unique_id='preview-mesh',
40
default_checked=True,
41
label=result_name,
42
delay=1000,
43
key=result_name
44
)
45
46
with col2:
47
button.send(
48
action='BakeGeometry',
49
data=result_json,
50
unique_id=f'bake_{result_name}',
51
key=result_name)
Copied!
Helper function to send a Honeybee model and the results as a colored mesh in Rhino
1
def visualize_model_with_mesh(hbjson_path: Path,
2
result_folders: List[Path] = None,
3
result_names: List[str] = None,
4
show_rhino_mesh: bool = False):
5
"""Visualize the Honeybee model in Rhino with colored mesh.
6
7
The result_folders and result_names accept a list of values. This is for the
8
reason that you can mount multiple results on the same model. An example would
9
be to mount the results of DA, sDA, and UDI on the same model.
10
11
args:
12
hbjson_path: Path to the HBJSON file.
13
result_folders: List of paths to the folder where the result files are written.
14
This is only used in creating colored mesh in Rhino.
15
result_names: List of names of the result files. This is only used in creating
16
colored mesh in Rhino. Defaults to None which means the names will be
17
assigned based on the order of the result files.
18
show_rhino_mesh: Boolean to show the mesh in Rhino or not. Defaults to False.
19
"""
20
21
hb_model = HBModel.from_hbjson(hbjson_path.as_posix())
22
rhino_hbjson(hb_model)
23
24
if show_rhino_mesh:
25
if not result_names:
26
result_names = [f'result_{i}' for i in range(len(result_folders))]
27
for count, result_folder in enumerate(result_folders):
28
rhino_mesh(hb_model, result_folder, result_names[count])
Copied!
Getting the host and saving in session state. Here, the host is Rhino. We need this to make the Streamlit app aware of the context. In this case, the Rhino environment.
1
st.session_state.host = special.get_host()
Copied!
Finally, visualizing the model and the results as a mesh in Rhino
1
with st.form('visualize-rhino'):
2
hbjson_path = Path(st.text_input('Path to HBJSON file'))
3
results_path = Path(st.text_input('Path to results folder'))
4
5
submit_button = st.form_submit_button(
6
label='Submit')
7
8
if submit_button:
9
visualize_model_with_mesh(hbjson_path, [results_path], [
10
'daylight-factor'], show_rhino_mesh=True)
Copied!

Testing the App inside Rhino

First, run the pollination app. Here, were assuming that the name of the python file for the app is "app" and the file is in the current working directory.

Running the App

1
streamlit run app.py
Copied!
This should run the app at the following location in your browser:
1
http://localhost:8501/
Copied!

Running the App inside Rhino

If you don't have already, download the Pollination Rhino plugin from here. Once you install the Rhino plugin, you should see the tabs for "Pollination" and "Pollination.Apps" in the sidebar of Rhino. If you don't, click on the gear icon shown in the image below;
Select the "Pollination" and "Pollination.Apps" on the menu that opens up
Next, click on the gear icon in Pollination.Apps. This will open up a new window.
In the panel, add the URL where the app is running and click on "Navigate to selection".
This should show the app inside Rhino.
Enter, the following values assuming the HBJSON file and the results are present in the current working directory. If not, provide full path to both.

Visualization in Rhino

Clicking the 'Submit" button should show the model and the mesh in Rhino that you can tun on and off and also bake as Rhino objects.