Examples¶
Short scripts from the
examples/
folder. Each one loads a sample model from
samples/,
so run them from the root of a clone of the repository. The code below is
included from the scripts themselves, so it matches the repository.
Read the model version¶
from dsbxml.utils import load_model
filepath = r".\samples\2026.1.0.013\Shoebox261.xml"
model = load_model(filepath)
print(model.version)
Load and save a model¶
from dsbxml.utils import load_model, save_model
filepath = r".\samples\8.0.0.058\DetailedHVAC.xml"
model = load_model(filepath)
save_model(model, r".\samples\8.0.0.058\DetailedHVAC_resaved.xml")
Zone geometry¶
Volume of the first zone¶
from dsbxml.utils import load_model
filepath = r".\samples\2026.1.0.013\Shoebox261.xml"
model = load_model(filepath)
site = model.site
first_building = site.buildings.building[0]
first_building_block = first_building.building_blocks.building_block[0]
first_zone = first_building_block.zones.zone[0]
body = first_zone.body
print(body.volume)
Read and move a vertex¶
from dsbxml.utils import load_model
filepath = r"samples\2026.1.0.013\Shoebox261.xml"
model = load_model(filepath)
site = model.site
first_building = site.buildings.building[0]
first_building_blocks = first_building.building_blocks.building_block[0]
first_zone = first_building_blocks.zones.zone[0]
vertices = first_zone.body.vertices
first_point = vertices[0]
print(first_point)
first_point.coords = [10, 0, 0]
print(first_point)
first_point.z = 20
print(first_point)
Zone names and floor polygons¶
from dsbxml.core import Body
from dsbxml.utils import load_model
filepath = r"samples\7.3.1.003\model from Tiago.xml"
dsb = load_model(filepath)
site = dsb.site
first_building = site.buildings.building[0]
def floor_faces(body: Body) -> list[list[list[float]]]:
"""List of floor faces, where each face is a list of x,y,z coordinates."""
vertices = [vertex.coords for vertex in body.vertices]
faces = []
for surface in body.surfaces.surface:
if surface.type == "Floor" and surface.vertex_indices:
vertex_indices = surface.vertex_indices.rstrip(";") # drop a trailing semicolon
indices = [int(x) for x in vertex_indices.split(";")]
faces.append([vertices[i] for i in indices])
return faces
def body_title(body: Body) -> str | None:
if body.attributes is None:
return None
for attribute in body.attributes.attribute:
if attribute.key == "Title":
return attribute.value
return None
for block in first_building.building_blocks.building_block:
if block.zones is None:
continue
for zone in block.zones.zone:
body = zone.body
print(body_title(body), floor_faces(body))
# if zone floor is not flat, for example has 2 surfaces or sloped
Tables¶
Each table row is one string of #-prefixed values in field_name order.
This example reads and changes a value in the Glazing table.
from dsbxml.utils import load_model
filepath = r".\samples\2026.1.0.013\Shoebox261.xml"
model = load_model(filepath)
tables = model.site.tables
glazing_table = tables.get_table_by_name("Glazing") # KeyError if missing
# Each row is one string of "#"-prefixed values, in field_name order.
# This split assumes no value contains "#".
print(glazing_table.field_name[:5])
def read_row(row: str) -> list[str]:
return [value.strip() for value in row.split("#")[1:]]
def write_row(values: list[str]) -> str:
return "#" + " #".join(values)
id_column = glazing_table.field_name.index("Id")
print([read_row(row)[id_column] for row in glazing_table.row]) # every Id
values = read_row(glazing_table.row[0])
print(values[id_column]) # Id of the first row
values[id_column] = "123" # set the Id of the first row
glazing_table.row[0] = write_row(values)
print(read_row(glazing_table.row[0])[id_column])
Detailed HVAC¶
Component types in the air and plant loops¶
from dsbxml.hvac.components import HVACComponent
from dsbxml.utils import load_model
def report_set(hc: HVACComponent):
texture = hc.image_rectangle.imageTextureIndex if hc.image_rectangle else None
return f"{hc.__class__.__name__} | {hc.type} | {hc.componentType} | {texture}"
filepath = r".\samples\8.0.0.058\DetailedHVAC.xml"
model = load_model(filepath)
building = model.site.buildings.building[0]
hvac_network = building.hvac_network
hvac_loops = hvac_network.hvac_loops.hvac_loop
hc_set = set()
for loop in hvac_loops:
for subloop in [loop.supply_sub_loop, loop.demand_sub_loop]:
for hc in subloop.hvac_components.hvac_component:
hc_set.add(report_set(hc))
for item in sorted(hc_set):
print(item)
Zone component types¶
from dsbxml.utils import load_model
def report_set(hc):
return f"{hc.__class__.__name__} | {hc.type} | {hc.componentType}"
filepath = r".\samples\8.0.0.058\DetailedHVAC.xml"
model = load_model(filepath)
building = model.site.buildings.building[0]
zone_groups = building.hvac_network.hvac_zone_groups.hvac_zone_group
hzc_set = set()
for zone_group in zone_groups:
if zone_group.zone_element_list is None:
continue
for hc in zone_group.zone_element_list.hvac_zone_component:
hzc_set.add(report_set(hc))
for item in sorted(hzc_set):
print(item)
Components inside zone units¶
from dsbxml.utils import load_model
def report_set(hc):
return f"{hc.__class__.__name__} | {hc.type} | {hc.componentType}"
filepath = r".\samples\8.0.0.058\DetailedHVAC.xml"
model = load_model(filepath)
building = model.site.buildings.building[0]
zone_groups = building.hvac_network.hvac_zone_groups.hvac_zone_group
hzc_set = set()
for zone_group in zone_groups:
if zone_group.zone_element_list is None:
continue
for hc in zone_group.zone_element_list.hvac_zone_component:
unit_element_list = getattr(hc, "unit_element_list", None)
if unit_element_list is not None:
for sub_hc in unit_element_list.hvac_component:
hzc_set.add(report_set(sub_hc))
for item in sorted(hzc_set):
print(item)
Zone groups and their zones¶
from dsbxml.utils import load_model
filepath = r".\samples\2025.1.0.095\HVAC_Zones_Coloured.xml"
model = load_model(filepath)
building = model.site.buildings.building[0]
def title(attributes) -> str:
if attributes is None:
return "Unknown"
return next((a.value for a in attributes.attribute if a.name == "Title"), "Unknown")
# Get all HVAC zone groups
zone_groups = building.hvac_network.hvac_zone_groups.hvac_zone_group
print(f"Found {len(zone_groups)} HVAC Zone Groups\n")
print("=" * 80)
for idx, zone_group in enumerate(zone_groups, 1):
print(f"\n{idx}. HVAC Zone Group: {title(zone_group.zone_group_attributes)}")
print("-" * 80)
# Get zone components in this group
if zone_group.zone_element_list:
zone_components = zone_group.zone_element_list.hvac_zone_component
if zone_components:
print(f" Zone Components ({len(zone_components)}):")
for component in zone_components:
print(f" - {title(component.attributes)}")
print(f" Type: {component.type or 'Unknown type'}")
else:
print(" No zone components in this group")
else:
print(" No ZoneElementList")
# Also show building zone handles if available
if zone_group.building_zone_handle_list:
zone_handles = zone_group.building_zone_handle_list.building_zone_handle
if zone_handles:
print(f" Building Zone Handles: {', '.join(zone_handles)}")
print("\n" + "=" * 80)
print(f"\nTotal Zone Groups: {len(zone_groups)}")