Skip to content

Commit

Permalink
fix(run): Update subprocess to-phpp write with variants
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Sep 12, 2022
1 parent 91653ec commit 6490888
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
21 changes: 14 additions & 7 deletions PHX/hbjson_to_phpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
import sys
import pathlib

from from_HBJSON import read_HBJSON_file, create_project
from PHX.from_HBJSON import read_HBJSON_file, create_project
from PHX.to_PHPP import phpp_app, xl_app
from PHX.to_PHPP.phpp_localization.shape_model import PhppShape

if __name__ == '__main__':

# --- Command line arguments
# -------------------------------------------------------------------------
SOURCE_FILE = pathlib.Path(sys.argv[1]).resolve()
LBT_PYTHON_SITE_PACKAGES = pathlib.Path(sys.argv[2]).resolve()
ACTIVATE_VARIANTS = pathlib.Path(sys.argv[3]).resolve()

# --- Read in an existing HB_JSON and re-build the HB Objects
# -------------------------------------------------------------------------
print("- " * 20)
print(f"> Reading in the HBJSON file: {SOURCE_FILE}")
print("- " * 50)
print(
f"> Reading in the HBJSON file: ./{SOURCE_FILE}")
hb_json_dict = read_HBJSON_file.read_hb_json_from_file(SOURCE_FILE)
hb_model = read_HBJSON_file.convert_hbjson_dict_to_hb_model(hb_json_dict)

Expand All @@ -31,15 +32,15 @@

# --- Connect to open instance of XL, Load the correct PHPP Shape file
# -------------------------------------------------------------------------
xl = xl_app.XLConnection = xl_app.XLConnection()
shape_file_dir = pathlib.Path(LBT_PYTHON_SITE_PACKAGES, "PHX", "to_PHPP", "phpp_localization")
xl = xl_app.XLConnection = xl_app.XLConnection(_output=print)
shape_file_dir = pathlib.Path("PHX", "to_PHPP", "phpp_localization")
phpp_shape_file = phpp_app.get_shape_file(xl, shape_file_dir)
phpp_shape = PhppShape.parse_file(phpp_shape_file)
phpp_conn = phpp_app.PHPPConnection(xl, phpp_shape)

if phpp_conn.xl.connection_is_open():
file = phpp_conn.xl.wb.name
print(f'[bold green]> connected to excel doc: {file}[/bold green]')
print(f'> connected to excel doc: {file}')

with phpp_conn.xl.in_silent_mode():
phpp_conn.xl.unprotect_all_sheets()
Expand All @@ -60,3 +61,9 @@
phpp_conn.write_project_volume(phx_project)
phpp_conn.write_project_hot_water(phx_project)
phpp_conn.write_project_res_elec_appliances(phx_project)

if ACTIVATE_VARIANTS == "True":
phpp_conn.activate_variant_assemblies()
phpp_conn.activate_variant_windows()
phpp_conn.activate_variant_ventilation()
phpp_conn.activate_variant_additional_vent()
17 changes: 13 additions & 4 deletions PHX/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,23 @@ def convert_hbjson_to_WUFI_XML(_hbjson_file, _save_file_name, _save_folder):
return directory, file_name


def write_hbjson_to_phpp(_hbjson_file, _lbt_python_site_packages_path):
# type: (str, str) -> None
def write_hbjson_to_phpp(_hbjson_file, _lbt_python_site_packages_path, _activate_variants="False"):
# type: (str, str, str) -> None
"""Read in an hbjson file and write out to a PHPP file.
Arguments:
---------
* _hbjson (str): File path to an HBJSON file to be read in and converted to a PHX-Model.
* _lbt_python_site_packages_path (str) The full path to the LBT Python-3 Site-packages
* _lbt_python_site_packages_path (str): The full path to the LBT Python-3 Site-packages
folder where PHX and Honeybee-PH are installed
* _activate_variants (str): Default="False". Set True if you would like to
connect all of the various PHPP inputs to the 'Variants' worksheet. This
is used when testing various combinations of attributes during the
early design phase. Note that if activated, any inputs will get overwritten
when the connection to the 'Variants' worksheet is made.
Note: Args must be strings, not actual boolean True/False.
"""

# -- Specify the path to the subprocess python script to run
Expand All @@ -116,6 +124,7 @@ def write_hbjson_to_phpp(_hbjson_file, _lbt_python_site_packages_path):
hb_folders.python_exe_path,
run_file_path,
_hbjson_file,
_lbt_python_site_packages_path
_lbt_python_site_packages_path,
_activate_variants
]
_run_subprocess(commands)
18 changes: 9 additions & 9 deletions _testing_to_PHPP.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf-8 -*-
# -*- Python Version: 3.7 -*-

"""DEV SANDBOX: export an HBJSON file to a PHPP XL file."""
"""DEV SANDBOX: export a specified HBJSON file to a PHPP XL file."""

import pathlib
from rich import print
import pathlib

from PHX.from_HBJSON import read_HBJSON_file, create_project
from PHX.to_PHPP import phpp_app, xl_app
from PHX.to_PHPP.phpp_localization.shape_model import PhppShape

if __name__ == '__main__':
# --- Input file Path
# -------------------------------------------------------------------------
SOURCE_FILE = pathlib.Path(
"sample/hbjson/220907_Chapman.hbjson"
)
# --- Input file Path
# -------------------------------------------------------------------------
SOURCE_FILE = pathlib.Path(
"/Users/em/Dropbox/bldgtyp-00/00_PH_Tools/PHX/tests/_source_hbjson/Default_Model_Single_Zone.hbjson"
)

if __name__ == '__main__':
# --- Read in an existing HB_JSON and re-build the HB Objects
# -------------------------------------------------------------------------
print("[bold green]- " * 50)
Expand Down Expand Up @@ -65,4 +65,4 @@
phpp_conn.activate_variant_assemblies()
phpp_conn.activate_variant_windows()
phpp_conn.activate_variant_ventilation()
phpp_conn.activate_variant_additional_vent()
phpp_conn.activate_variant_additional_vent()

0 comments on commit 6490888

Please sign in to comment.