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

# Using Eppy to export IDF objects

I am trying to pre-process an IDF file (exported from DesignBuilder or OpenStudio) to use it with jEPlus. Thanks to the help I received on this forum I have managed to replace selected parameters with jEPlus variables, which is great.

My next step is to 'assemble' an IDF file, by:

• extracting objects from an IDF files
• saving them as a separate IDF files (or INP input file) to be subsequently called by EP-macro, within jEPlus.

For instance, I would like to use the geometry built with DesignBuilder - by extracting idf.idfobjects['BUILDINGSURFACE:DETAILED'] - and copy this in a new file where all other objects are called through EP-macro (i.e. schedules, materials, output variables etc).

Also, could these objets be exported in a different format, (i.e. CSV) in order to visualise them? I have tried to use the commands .saveas() and .to_csv in eppy but neither of those seem to work.

edit retag close merge delete

Sort by » oldest newest most voted

For the first question, you can create a second IDF and add the extracted objects to it.

# get the geometry objects
surfaces = idf.idfobjects['BUILDINGSURFACE:DETAILED']
windows = idf.idfobjects['WINDOW']

# make a new empty IDF
idf2 = IDF()
idf2.new()

# copy the geometry objects into the new IDF
for s, w in zip(surfaces, windows):
idf2.copyidfobject(s)
idf2.copyidfobject(w)

# save the geometry as an IMF for use by EPMacro
idf2.saveas('geometry.imf')


For the second question, IDF.saveas() is just to change the filename. It doesn't really make sense to save it as a CSV since each object has different fields. I suppose you could do something like:

headers = surfaces[0].objls  # get the column headers as a list
rows = [s.obj for s in surfaces] # get the values as a list of lists
with open('out.csv', 'w') as f_out:
f_out.write(','.join(str(i) for i in headers) + '\n')
for row in rows:
f_out.write(','.join(str(i) for i in row) + '\n')


Alternatively you could open up the IDF in the OpenStudio SketchUp plugin to get a visualisation of the surfaces and windows in the model.

In response to your comment, you need to tell eppy which output variable you want to remove from the IDF. The simple case first:

# to remove them all
for variable in idf.idfobjects['OUTPUT:VARIABLE']:
idf.removeidfobject(variable)


Removing a specific variable can be a bit tricky though. Since they don't have a Name field we can't select them using idf.getobject('OUTPUT:VARIABLE', name). They do have a Key_Value field, though this is often *, and a Variable_Name field. We can use those in a list comprehension to filter out the variable or variables to remove.

# to remove all variables of a given Variable_Name
name = "Electric Equipment Electric Energy"
variables = [v for v in idf.idfobjects['OUTPUT:VARIABLE'] if v.Variable_Name == name]
for variable in variables :
idf.removeidfobject(variable)

# to remove variables with a given Variable_Name with a specific Key_Value
key_value = "PrimaryHeater"
name = "Boiler Gas Energy"
variables = [v for v in idf.idfobjects['OUTPUT:VARIABLE']
if v.Variable_Name == name
and v.Key_Value == key_value]
for variable in variables :
idf.removeidfobject(variable)

more

1

Jamie, thanks very much for your answer. Similarly, is there a way to drop selected IDF objects in Eppy? I have tried idf.removeidfobject('OUTPUT:VARIABLE') but that does not seem to work

( 2016-08-15 10:33:58 -0500 )edit

I've edited the answer to cover your situation. OUTPUT:VARIABLEs are a tricky example but there's a few ways to do it.

( 2016-08-15 12:31:46 -0500 )edit

I have tried to use the code you suggested to remove all output variables:

for variable in idf.idfobjects['OUTPUT:VARIABLE']:
idf.removeidfobject(variable)


but nearly half of the variables remain.

Some might argue that it does not matter how many variables are there, as what matters is actually what one instructs jeplus to collect through the rvi/rvx. While that is true, I find that sometimes I need to go through the .eso files (for any of the iterations) to explore the results, and I find having too many irrelevant output variables very confusing.

( 2016-08-17 12:38:46 -0500 )edit

Would it be possible for me to remove variables whose Variable_Name or Key_Value contain a specific string, rather than perfect name matching? (Don't hate me! :) )

( 2016-08-17 12:41:23 -0500 )edit

Interesting that not everything gets removed in the simple case. Not sure why that is. In general, all this stuff about output variables should really be in another question though. It's nothing to do with the original question here so no-one in future is likely to be able to find it.

( 2016-08-17 14:43:34 -0500 )edit

Please start posting anonymously - your entry will be published after you log in or create a new account.