Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

Here's a lightly tested Python script (using eppy) for EnergyPlus. Depending on your model, you may want to add filters (e.g. Construction:InternalSource, Material:NoMass, etc.).

import os
from eppy.modeleditor import IDF

idd_dir = r'C:\EnergyPlusV9-1-0'
idd_file = r'Energy+.idd'
idd_path = os.path.join(idd_dir, idd_file)

idf_dir = r'C:\WORK\18151 DEN Level 4\18151-Baseline\run'
idf_file = r'in.idf'
idf_path = os.path.join(idf_dir, idf_file)

IDF.setiddname(idd_path)

idf = IDF(idf_path)

total_heat_capacity = 0

surfaces = idf.idfobjects['BuildingSurface:Detailed'.upper()] 

# loop through the surfaces to calculate heat capacity
for surface in surfaces:

    construction_heat_capacity = 0

    construction = idf.getobject('CONSTRUCTION', surface.Construction_Name)

    # get the field names, which is a list of ['key', 'Name', 'Outside_Layer', 'Layer_2', ... 'Layer_10']
    construction_field_names = construction.fieldnames

    # loop through the construction's field names (layers), skipping first and second (key and Name)
    for field_name in construction_field_names[2:]:

        # get the material object from the layer
        attribute = field_name
        material_name = getattr(construction, attribute)
        material = idf.getobject('MATERIAL', material_name)

        # calculate the material's heat capacity and add it to the construction's
        if material is not None:
            thickness = material.Thickness
            density = material.Density
            specific_heat = material.Specific_Heat
            material_heat_capacity = thickness * density * specific_heat
            construction_heat_capacity += material_heat_capacity

    # add the construction's total heat capacity to the model's total
    total_heat_capacity += construction_heat_capacity

print('J/m2*K =', total_heat_capacity)

References from OpenStudio

Here's a lightly tested Python script (using eppy) for EnergyPlus. Depending on your model, you may want to add filters (e.g. Construction:InternalSource, Material:NoMass, etc.).

import os
from eppy.modeleditor import IDF

idd_dir = r'C:\EnergyPlusV9-1-0'
idd_file = r'Energy+.idd'
idd_path = os.path.join(idd_dir, idd_file)

idf_dir = r'C:\WORK\18151 DEN Level 4\18151-Baseline\run'
idf_file = r'in.idf'
idf_path = os.path.join(idf_dir, idf_file)

IDF.setiddname(idd_path)

idf = IDF(idf_path)

total_heat_capacity = 0

surfaces = idf.idfobjects['BuildingSurface:Detailed'.upper()] 

# loop through the surfaces to calculate heat capacity
for surface in surfaces:

    construction_heat_capacity = 0

    construction = idf.getobject('CONSTRUCTION', surface.Construction_Name)

    # get the field names, which is a list of 
    # ['key', 'Name', 'Outside_Layer', 'Layer_2', ... 'Layer_10']
    construction_field_names = construction.fieldnames

    # loop through the construction's field names (layers), 
    # skipping first and second (key and Name)
    for field_name in construction_field_names[2:]:

        # get the material object from the layer
        attribute = field_name
        material_name = getattr(construction, attribute)
        material = idf.getobject('MATERIAL', material_name)

        # calculate the material's heat capacity and add it to the construction's
        if material is not None:
            thickness = material.Thickness
            density = material.Density
            specific_heat = material.Specific_Heat
            material_heat_capacity = thickness * density * specific_heat
            construction_heat_capacity += material_heat_capacity

    # add the construction's total heat capacity to the model's total
    total_heat_capacity += construction_heat_capacity

print('J/m2*K =', total_heat_capacity)

References from OpenStudio

To do it programmatically, you could either use OpenStudio and Ruby or EnergyPlus and Python.

OpenStudio and Ruby

Import the IDF to OpenStudio and as @luis lara suggested run a Ruby script (or formal OpenStudio Measure) on the OpenStudio model

EnergyPlus and Python

Here's a lightly tested Python script (using eppy) for EnergyPlus. Depending on your model, you may want to add filters (e.g. Construction:InternalSource, Material:NoMass, etc.).

import os
from eppy.modeleditor import IDF

idd_dir = r'C:\EnergyPlusV9-1-0'
idd_file = r'Energy+.idd'
idd_path = os.path.join(idd_dir, idd_file)

idf_dir = r'C:\WORK\18151 DEN Level 4\18151-Baseline\run'
idf_file = r'in.idf'
idf_path = os.path.join(idf_dir, idf_file)

IDF.setiddname(idd_path)

idf = IDF(idf_path)

total_heat_capacity = 0

surfaces = idf.idfobjects['BuildingSurface:Detailed'.upper()] 

# loop through the surfaces to calculate heat capacity
for surface in surfaces:

    construction_heat_capacity = 0

    construction = idf.getobject('CONSTRUCTION', surface.Construction_Name)

    # get the field names, which is a list of 
    # ['key', 'Name', 'Outside_Layer', 'Layer_2', ... 'Layer_10']
    construction_field_names = construction.fieldnames

    # loop through the construction's field names (layers), 
    # skipping first and second (key and Name)
    for field_name in construction_field_names[2:]:

        # get the material object from the layer
        attribute = field_name
        material_name = getattr(construction, attribute)
        material = idf.getobject('MATERIAL', material_name)

        # calculate the material's heat capacity and add it to the construction's
        if material is not None:
            thickness = material.Thickness
            density = material.Density
            specific_heat = material.Specific_Heat
            material_heat_capacity = thickness * density * specific_heat
            construction_heat_capacity += material_heat_capacity

    # add the construction's total heat capacity to the model's total
    total_heat_capacity += construction_heat_capacity

print('J/m2*K =', total_heat_capacity)

References from OpenStudio

To do it programmatically, you could either use OpenStudio and Ruby or EnergyPlus and Python.

OpenStudio and Ruby

Import the IDF to OpenStudio and as @luis lara suggested run a Ruby script (or formal OpenStudio Measure) on the OpenStudio modelmodel.

EnergyPlus and Python

Here's a lightly tested Python script (using eppy) for EnergyPlus. ). Depending on your model, you may want to add filters (e.g. Construction:InternalSource, Material:NoMass, etc.).

import os
from eppy.modeleditor import IDF

idd_dir = r'C:\EnergyPlusV9-1-0'
idd_file = r'Energy+.idd'
idd_path = os.path.join(idd_dir, idd_file)

idf_dir = r'C:\WORK\18151 DEN Level 4\18151-Baseline\run'
idf_file = r'in.idf'
idf_path = os.path.join(idf_dir, idf_file)

IDF.setiddname(idd_path)

idf = IDF(idf_path)

total_heat_capacity = 0

surfaces = idf.idfobjects['BuildingSurface:Detailed'.upper()] 

# loop through the surfaces to calculate heat capacity
for surface in surfaces:

    construction_heat_capacity = 0

    construction = idf.getobject('CONSTRUCTION', surface.Construction_Name)

    # get the field names, which is a list of 
    # ['key', 'Name', 'Outside_Layer', 'Layer_2', ... 'Layer_10']
    construction_field_names = construction.fieldnames

    # loop through the construction's field names (layers), 
    # skipping first and second (key and Name)
    for field_name in construction_field_names[2:]:

        # get the material object from the layer
        attribute = field_name
        material_name = getattr(construction, attribute)
        material = idf.getobject('MATERIAL', material_name)

        # calculate the material's heat capacity and add it to the construction's
        if material is not None:
            thickness = material.Thickness
            density = material.Density
            specific_heat = material.Specific_Heat
            material_heat_capacity = thickness * density * specific_heat
            construction_heat_capacity += material_heat_capacity

    # add the construction's total heat capacity to the model's total
    total_heat_capacity += construction_heat_capacity

print('J/m2*K =', total_heat_capacity)

References from OpenStudio

To do it programmatically, you could either use OpenStudio and Ruby or EnergyPlus and Python.

OpenStudio and Ruby

Import the IDF to OpenStudio and as @luis lara suggested run a Ruby script (or formal OpenStudio Measure) on the OpenStudio model.

EnergyPlus and Python

Here's a lightly tested Python script (using eppy). Depending on your model, you may want to add filters (e.g. Construction:InternalSource, Material:NoMass, etc.).

import os
from eppy.modeleditor import IDF

idd_dir = r'C:\EnergyPlusV9-1-0'
idd_file = r'Energy+.idd'
idd_path = os.path.join(idd_dir, idd_file)

idf_dir = r'C:\WORK\18151 DEN Level 4\18151-Baseline\run'
idf_file = r'in.idf'
idf_path = os.path.join(idf_dir, idf_file)

IDF.setiddname(idd_path)

idf = IDF(idf_path)

total_heat_capacity = 0

surfaces = idf.idfobjects['BuildingSurface:Detailed'.upper()] 

# loop through the surfaces to calculate heat capacity
for surface in surfaces:

    construction_heat_capacity = 0

    construction = idf.getobject('CONSTRUCTION', surface.Construction_Name)

    # get the field names, which in eppy is a list of 
    # ['key', 'Name', 'Outside_Layer', 'Layer_2', ... 'Layer_10']
    construction_field_names = construction.fieldnames

    # loop through the construction's field names (layers), 
    # skipping first and second (key and Name)
    for field_name in construction_field_names[2:]:

        # get the material object from the layer
        attribute = field_name
        material_name = getattr(construction, attribute)
        material = idf.getobject('MATERIAL', material_name)

        # calculate the material's heat capacity and add it to the construction's
        if material is not None:
            thickness = material.Thickness
            density = material.Density
            specific_heat = material.Specific_Heat
            material_heat_capacity = thickness * density * specific_heat
            construction_heat_capacity += material_heat_capacity

    # add the construction's total heat capacity to the model's total
    total_heat_capacity += construction_heat_capacity

print('J/m2*K =', total_heat_capacity)

References from OpenStudio