forked from ladybug-tools/honeybee-grasshopper-core
/
HB_Dump_gbXML.json
64 lines (64 loc) · 5.84 KB
/
HB_Dump_gbXML.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
"version": "1.4.1",
"nickname": "DumpGBXML",
"outputs": [
[
{
"access": "None",
"name": "gbxml",
"description": "The location of the file where the honeybee JSON is saved.",
"type": null,
"default": null
}
]
],
"inputs": [
{
"access": "item",
"name": "_model",
"description": "A Honeybee Model object to be written to a gbXML file.",
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "_name_",
"description": "A name for the file to which the honeybee objects will be written.\nIf unspecified, it will be derived from the model identifier.",
"type": "string",
"default": null
},
{
"access": "item",
"name": "_folder_",
"description": "An optional directory into which the honeybee objects will be\nwritten. The default is set to the default simulation folder.",
"type": "string",
"default": null
},
{
"access": "item",
"name": "triangulate_",
"description": "Boolean to note whether sub-faces (including Apertures and Doors)\nshould be triangulated if they have more than 4 sides (True) or\nwhether they should be left as they are (False). This triangulation\nis necessary when exporting directly to EnergyPlus since it cannot\naccept sub-faces with more than 4 vertices. However, it is not a\ngeneral requirement of gbXML or all of the simulation engines that\ngbXML can import to/from. (Default: False).",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "full_geo_",
"description": "Boolean to note whether space boundaries and shell geometry should\nbe included in the exported gbXML vs. just the minimal required\nnon-manifold geometry. Setting to True to include the full geometry\nwill increase file size without adding much new infomration that\ndoesn't already exist in the file. However, some gbXML interfaces\nneed this geometry in order to properly represent and display\nroom volumes. (Default: False).",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "_dump",
"description": "Set to \"True\" to save the honeybee model to a gbXML file.",
"type": "bool",
"default": null
}
],
"subcategory": "3 :: Serialize",
"code": "\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.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 # remove colinear vertices using the Model tolerance to avoid E+ tolerance issues\n for room in _model.rooms:\n room.remove_colinear_vertices_envelope(_model.tolerance)\n # scale the model if the units are not meters\n if _model.units != 'Meters':\n _model.convert_to_units('Meters')\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 with open(hb_file, 'w') as fp:\n json.dump(model_dict, fp)\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 raise Exception('Running OpenStudio CLI failed.')\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",
"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-"
}