@@ -1295,7 +1295,9 @@ def model_to_idf(
12951295def model_to_gbxml (
12961296 model , triangulate_non_planar_orphaned = True , triangulate_subfaces = False ,
12971297 full_geometry = False , interior_face_type = None , ground_face_type = None ,
1298- program_name = None , program_version = None , print_progress = False
1298+ reset_geometry_ids = False , reset_resource_ids = False ,
1299+ program_name = None , program_version = None , gbxml_schema_version = None ,
1300+ print_progress = False
12991301):
13001302 """Translate a Honeybee Model to gbXML string using OpenStudio SDK translators.
13011303
@@ -1320,6 +1322,22 @@ def model_to_gbxml(
13201322 ground_face_type: Text string for the type to be used for all ground-contact
13211323 floor faces. If unspecified, the ground types will be left as they are.
13221324 Choose from the following. UndergroundSlab, SlabOnGrade, RaisedFloor.
1325+ reset_geometry_ids: Boolean to note whether a cleaned version of geometry
1326+ display names should be used for the IDs that appear within
1327+ the gbXML file. Using this flag will affect all Rooms, Faces,
1328+ Apertures, Doors, and Shades. It will generally result in more
1329+ read-able IDs in the gbXML file but this means that it will not be
1330+ easy to map results back to the input Model. Cases of duplicate IDs
1331+ resulting from non-unique names will be resolved by adding integers
1332+ to the ends of the new IDs that are derived from the name. (Default: False).
1333+ reset_resource_ids: Boolean to note whether a cleaned version of all
1334+ resource display names should be used for the IDs that appear within
1335+ the gbXML file. Using this flag will affect all Materials,
1336+ Constructions, ConstructionSets, Schedules, Loads, and ProgramTypes.
1337+ It will generally result in more read-able names for the resources
1338+ in the gbXML file. Cases of duplicate IDs resulting from non-unique
1339+ names will be resolved by adding integers to the ends of the new
1340+ IDs that are derived from the name. (Default: False).
13231341 program_name: Optional text to set the name of the software that will
13241342 appear under the programId and ProductName tags of the DocumentHistory
13251343 section. This can be set things like "Ladybug Tools" or "Pollination"
@@ -1330,6 +1348,9 @@ def model_to_gbxml(
13301348 program_name is also unspecified, only the version of OpenStudio will
13311349 appear. Otherwise, this will default to "0.0.0" given that the version
13321350 field is required. (Default: None).
1351+ gbxml_schema_version: Optional text to set the version of the gbXML schema
1352+ that is specified in the XML header (eg. "5.00"). If None, this
1353+ will default to the latest version.
13331354 print_progress: Set to True to have the progress of the translation
13341355 printed as it is completed. (Default: False).
13351356 """
@@ -1362,7 +1383,9 @@ def model_to_gbxml(
13621383
13631384 # translate the Honeybee Model to an OpenStudio Model
13641385 os_model = model_to_openstudio (
1365- model , triangulate_non_planar_orphaned = triangulate_non_planar_orphaned ,
1386+ model ,
1387+ use_geometry_names = reset_geometry_ids , use_resource_names = reset_resource_ids ,
1388+ triangulate_non_planar_orphaned = triangulate_non_planar_orphaned ,
13661389 triangulate_subfaces = triangulate_subfaces ,
13671390 use_simple_window_constructions = True , print_progress = print_progress
13681391 )
@@ -1375,6 +1398,7 @@ def model_to_gbxml(
13751398 gbxml_str = gbxml_translator .modelToGbXMLString (os_model )
13761399
13771400 # set the program_name in the DocumentHistory if specified
1401+ split_lines = None
13781402 if program_name is not None :
13791403 split_lines = gbxml_str .split ('\n ' )
13801404 hist_start_i , hist_end_i = None , None
@@ -1398,6 +1422,27 @@ def model_to_gbxml(
13981422 split_lines [hist_start_i :hist_end_i + 1 ] = d_hst
13991423 gbxml_str = '\n ' .join (split_lines )
14001424
1425+ # set the gbXML schema version in the header if specified
1426+ SCHEMA_VERSIONS = ('0.35' , '0.36' , '0.37' , '5.00' , '5.01' ,
1427+ '5.10' , '5.11' , '5.12' , '6.00' , '6.01' , '7.03' )
1428+ now_ver = SCHEMA_VERSIONS [- 1 ]
1429+ if gbxml_schema_version is not None and gbxml_schema_version != now_ver :
1430+ if gbxml_schema_version not in SCHEMA_VERSIONS :
1431+ if print_progress :
1432+ print (
1433+ 'The specified gbXML schema version is not recognized. '
1434+ 'Defaulting to {}. Please choose '
1435+ 'from the following: {}' .format (now_ver , ', ' .join (SCHEMA_VERSIONS ))
1436+ )
1437+ else :
1438+ split_lines = gbxml_str .split ('\n ' ) if split_lines is None else split_lines
1439+ template = 'http://gbxml.org/schema/{}/GreenBuildingXML_Ver{}.xsd'
1440+ base_ver = template .format (now_ver .replace ('.' , '-' ), now_ver )
1441+ new_ver = template .format (gbxml_schema_version .replace ('.' , '-' ),
1442+ gbxml_schema_version )
1443+ split_lines [1 ] = split_lines [1 ].replace (base_ver , new_ver )
1444+ gbxml_str = '\n ' .join (split_lines )
1445+
14011446 # replace all interior floors with the specified type
14021447 if interior_face_type == 'InteriorFloor' :
14031448 gbxml_str = gbxml_str .replace ('="Ceiling"' , '="InteriorFloor"' )
0 commit comments