-
Notifications
You must be signed in to change notification settings - Fork 66
Examples
This example will show a quick method to grab all objects from an idf and find all object's names. A list of all objects is created and each object is queried for a 'Name' attribute.
Working with eppy requires the following imports
import eppy
from eppy.modeleditor import IDF
To work with the IDF class, the user must specify which version of EnergyPlus is to be used. This is done by passing the iddfile to the IDF argument setiddname. Once set, the pass the IDF class the name of the EnergyPlus input file
iddfile = "/usr/local/EnergyPlus-8-0-0/Energy+.idd" # absolute path to Energy+.idd
IDF.setiddname(iddfile) # only do this once
idf = IDF("my_energyplus_file.idf")
# Alternatively you can use a try/except clause: https://wiki.python.org/moin/HandlingExceptions
# This will save some headaches if you're using an IPython Notebook:http://ipython.org/notebook.html
try:
IDF.setiddname('/Applications/EnergyPlus-8-1-0/Energy+.idd')
except modeleditor.IDDAlreadySetError as e:
pass
Now to get all the non-empty objects from the idf
all_objects_list = [obj[1] for obj in idf.idfobjects.iteritems() if len(obj[1]) > 0]
all_objects_list;
This list will be nested. For example, if there are more than 1 walls in the idf, all of these will lie in a list nested in the BuildingSurfaceDetailed dictionary. To kick this chick from the nest and make it fly;
all_objects = [x for lst in all_objects_list for x in lst]
Finally, lets grab all the names in this list of objects. Not all objects have a name attribute, hence the try and except.
list_of_names = []
for obj in all_objects:
try:
n = getattr(obj, 'Name')
list_of_names.append(n)
except:
pass
(from issue #36: https://github.com/santoshphilip/eppy/issues/36)
This code will require the following imports:
from eppy import readhtml
import pandas as pf
This code snippet is from @amaliahicks
for file in files:
filehandle = open(filename,'r').read()
htables=readhtml.titletable(filehandle)
alltitles = [htable[0] for htable in htables]
ltables = readhtml.lines_table(filehandle) # reads the tables with their titles
for ltable in ltables:
if "End Uses" in '\n'.join(ltable[0]) and "End Uses By Subcategory" not in '\n'.join(ltable[0]):
atable=ltable[-1]
df=pf.DataFrame(atable)
Also see: https://github.com/eayoungs/EPlusTemplates/blob/public/Scripting/readhtml.ipynb