Skip to content

Commit

Permalink
fix(serialize): Expose an option for only using interior floors
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Mar 11, 2024
1 parent 41dbb7a commit 903e5be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Binary file modified honeybee_grasshopper_core/icon/HB Dump gbXML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions honeybee_grasshopper_core/json/HB_Dump_gbXML.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.7.0",
"version": "1.7.1",
"nickname": "DumpGBXML",
"outputs": [
[
Expand Down Expand Up @@ -34,6 +34,13 @@
"type": "string",
"default": null
},
{
"access": "item",
"name": "x",
"description": "A boolean to note whether all interior horizontal faces should\nbe written with the InteriorFloor type instead of the combination\nof InteriorFloor and Ceiling that happens by default with OpenStudio\ngbXML serialization. (Default: False).",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "triangulate_",
Expand All @@ -57,7 +64,7 @@
}
],
"subcategory": "3 :: Serialize",
"code": "\nimport sys\nimport os\nimport json\n\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the honeybee_energy dependencies\n from honeybee_energy.result.osw import OSW\n from honeybee_energy.run import to_gbxml_osw, run_osw, add_gbxml_space_boundaries\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from lbt_recipes.version import check_openstudio_version\nexcept ImportError as e:\n raise ImportError('\\nFailed to import lbt_recipes:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _dump:\n # check the presence of openstudio and check that the version is compatible\n check_openstudio_version()\n\n # check the input and set the component defaults\n assert isinstance(_model, Model), \\\n 'Excpected Honeybee Model object. Got {}.'.format(type(_model))\n name = _name_ if _name_ is not None else _model.identifier\n lower_name = name.lower()\n gbxml_file = name if lower_name.endswith('.xml') or lower_name.endswith('.gbxml') \\\n else '{}.xml'.format(name)\n folder = _folder_ if _folder_ is not None else folders.default_simulation_folder\n gbxml = os.path.join(folder, gbxml_file)\n\n # duplicate model to avoid mutating it as we edit it for energy simulation\n _model = _model.duplicate()\n # scale the model if the units are not meters\n _model.convert_to_units('Meters')\n # remove degenerate geometry within native E+ tolerance of 1 cm\n _model.remove_degenerate_geometry(0.01)\n\n # write out the HBJSON and OpenStudio Workflow (OSW) that translates models to gbXML\n out_directory = os.path.join(folders.default_simulation_folder, 'temp_translate')\n if not os.path.isdir(out_directory):\n os.makedirs(out_directory)\n triangulate_ = False if triangulate_ is None else triangulate_\n model_dict = _model.to_dict(included_prop=['energy'], triangulate_sub_faces=triangulate_)\n _model.properties.energy.add_autocal_properties_to_dict(model_dict)\n _model.properties.energy.simplify_window_constructions_in_dict(model_dict)\n hb_file = os.path.join(out_directory, '{}.hbjson'.format(_model.identifier))\n if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8\n with open(hb_file, 'wb') as fp:\n obj_str = json.dumps(model_dict, indent=4, ensure_ascii=False)\n fp.write(obj_str.encode('utf-8'))\n else:\n with open(hb_file, 'w', encoding='utf-8') as fp:\n obj_str = json.dump(model_dict, fp, indent=4, ensure_ascii=False)\n osw = to_gbxml_osw(hb_file, gbxml, out_directory)\n\n # run the measure to translate the model JSON to an openstudio measure\n osm, idf = run_osw(osw, silent=True)\n if idf is None:\n log_osw = OSW(os.path.join(out_directory, 'out.osw'))\n raise Exception(\n 'Failed to run OpenStudio CLI:\\n{}'.format('\\n'.join(log_osw.errors)))\n\n # add in the space boundary geometry if the user has requested it\n if full_geo_:\n add_gbxml_space_boundaries(gbxml, _model)\n",
"code": "\nimport sys\nimport os\nimport json\n\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the honeybee_energy dependencies\n from honeybee_energy.result.osw import OSW\n from honeybee_energy.run import to_gbxml_osw, run_osw, set_gbxml_floor_types, \\\n add_gbxml_space_boundaries\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\n from lbt_recipes.version import check_openstudio_version\nexcept ImportError as e:\n raise ImportError('\\nFailed to import lbt_recipes:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _dump:\n # check the presence of openstudio and check that the version is compatible\n check_openstudio_version()\n\n # check the input and set the component defaults\n assert isinstance(_model, Model), \\\n 'Excpected Honeybee Model object. Got {}.'.format(type(_model))\n name = _name_ if _name_ is not None else _model.identifier\n lower_name = name.lower()\n gbxml_file = name if lower_name.endswith('.xml') or lower_name.endswith('.gbxml') \\\n else '{}.xml'.format(name)\n folder = _folder_ if _folder_ is not None else folders.default_simulation_folder\n gbxml = os.path.join(folder, gbxml_file)\n\n # duplicate model to avoid mutating it as we edit it for energy simulation\n _model = _model.duplicate()\n # scale the model if the units are not meters\n _model.convert_to_units('Meters')\n # remove degenerate geometry within native E+ tolerance of 1 cm\n _model.remove_degenerate_geometry(0.01)\n\n # write out the HBJSON and OpenStudio Workflow (OSW) that translates models to gbXML\n out_directory = os.path.join(folders.default_simulation_folder, 'temp_translate')\n if not os.path.isdir(out_directory):\n os.makedirs(out_directory)\n triangulate_ = False if triangulate_ is None else triangulate_\n model_dict = _model.to_dict(included_prop=['energy'], triangulate_sub_faces=triangulate_)\n _model.properties.energy.add_autocal_properties_to_dict(model_dict)\n _model.properties.energy.simplify_window_constructions_in_dict(model_dict)\n hb_file = os.path.join(out_directory, '{}.hbjson'.format(_model.identifier))\n if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8\n with open(hb_file, 'wb') as fp:\n obj_str = json.dumps(model_dict, indent=4, ensure_ascii=False)\n fp.write(obj_str.encode('utf-8'))\n else:\n with open(hb_file, 'w', encoding='utf-8') as fp:\n obj_str = json.dump(model_dict, fp, indent=4, ensure_ascii=False)\n osw = to_gbxml_osw(hb_file, gbxml, out_directory)\n\n # run the measure to translate the model JSON to an openstudio measure\n osm, idf = run_osw(osw, silent=True)\n if idf is None:\n log_osw = OSW(os.path.join(out_directory, 'out.osw'))\n raise Exception(\n 'Failed to run OpenStudio CLI:\\n{}'.format('\\n'.join(log_osw.errors)))\n\n # add in the space boundary geometry or reset floor types if the user requested it\n if int_floors_:\n set_gbxml_floor_types(gbxml, interior_type='InteriorFloor')\n if full_geo_:\n add_gbxml_space_boundaries(gbxml, _model)\n",
"category": "Honeybee",
"name": "HB Dump gbXML",
"description": "Dump a Honyebee Model to a gbXML file.\n_\nThe gbXML format is a common open standard used to transfer energy model geometry\nand (some) energy simulation properties from one simulation environment to another.\n_\nThe forward translators within the OpenStudio SDK are used to export all Honeybee\nmodel geometry and properties.\n-"
Expand Down
13 changes: 10 additions & 3 deletions honeybee_grasshopper_core/src/HB Dump gbXML.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
If unspecified, it will be derived from the model identifier.
_folder_: An optional directory into which the honeybee objects will be
written. The default is set to the default simulation folder.
int_floors_: A boolean to note whether all interior horizontal faces should
be written with the InteriorFloor type instead of the combination
of InteriorFloor and Ceiling that happens by default with OpenStudio
gbXML serialization. (Default: False).
triangulate_: Boolean to note whether sub-faces (including Apertures and Doors)
should be triangulated if they have more than 4 sides (True) or
whether they should be left as they are (False). This triangulation
Expand All @@ -47,7 +51,7 @@

ghenv.Component.Name = 'HB Dump gbXML'
ghenv.Component.NickName = 'DumpGBXML'
ghenv.Component.Message = '1.7.0'
ghenv.Component.Message = '1.7.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '3 :: Serialize'
ghenv.Component.AdditionalHelpFromDocStrings = '4'
Expand All @@ -64,7 +68,8 @@

try: # import the honeybee_energy dependencies
from honeybee_energy.result.osw import OSW
from honeybee_energy.run import to_gbxml_osw, run_osw, add_gbxml_space_boundaries
from honeybee_energy.run import to_gbxml_osw, run_osw, set_gbxml_floor_types, \
add_gbxml_space_boundaries
except ImportError as e:
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

Expand Down Expand Up @@ -125,6 +130,8 @@
raise Exception(
'Failed to run OpenStudio CLI:\n{}'.format('\n'.join(log_osw.errors)))

# add in the space boundary geometry if the user has requested it
# add in the space boundary geometry or reset floor types if the user requested it
if int_floors_:
set_gbxml_floor_types(gbxml, interior_type='InteriorFloor')
if full_geo_:
add_gbxml_space_boundaries(gbxml, _model)
Binary file modified honeybee_grasshopper_core/user_objects/HB Dump gbXML.ghuser
Binary file not shown.

0 comments on commit 903e5be

Please sign in to comment.