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

Revision history [back]

I doubt you are going to be critically bound with I/O here, so the quickest workaround is to save to a file then read it with python. Otherwise, the code use to save is pretty simple and located modeleditor.py#L907:L953. You can easily modify that to only keep the string.

Let's load some dummy data, and two system modules we will optionally need to encode:

import platform
import os
from eppy import modeleditor
from eppy.modeleditor import IDF

# Set Idd
iddfile = r'/usr/local/EnergyPlus-9-0-1/Energy+.idd'
IDF.setiddname(iddfile)

# Load example file
p = r'/usr/local/EnergyPlus-9-0-1/ExampleFiles/1ZoneUncontrolled.idf'
idf1 = IDF(p)

Now here's the thing:

# Get the idf as a string
s = idf1.idfstr()

# **Do stuff here**

# Optional Encoding like eppy would do by default (lineendings = 'default', encoding='latin-1') 
encoding = 'latin-1'
system = platform.system()
s = '!- {} Line endings \n'.format(system) + s
slines = s.splitlines()
# Make it a single string
s = os.linesep.join(slines)
s = s.encode(encoding)
# s is your idf string

# **Or do stuff here**

TL;DR: use the IDF::idfstr() method to get the string, then output that to a file once you're done.


I doubt you are going to be critically bound with I/O here, so the quickest workaround is to save to a file then read it with python. Otherwise, the code use to save is pretty simple and located modeleditor.py#L907:L953. You can easily modify that to only keep the string.string via IDF::idfstr() method, do stuff on it, and still save ultimately in the same format that eppy does.

Let's load some dummy data, and two system modules we will optionally need to encode:

import platform
import os
from eppy import modeleditor
from eppy.modeleditor import IDF

# Set Idd
iddfile = r'/usr/local/EnergyPlus-9-0-1/Energy+.idd'
IDF.setiddname(iddfile)

# Load example file
p = r'/usr/local/EnergyPlus-9-0-1/ExampleFiles/1ZoneUncontrolled.idf'
idf1 = IDF(p)

Now here's the thing:

# Get the idf as a string
s = idf1.idfstr()

# **Do stuff here**

# Optional Encoding like eppy would do by default (lineendings = 'default', encoding='latin-1') 
encoding = 'latin-1'
system = platform.system()
s = '!- {} Line endings \n'.format(system) + s
slines = s.splitlines()
# Make it a single string
s = os.linesep.join(slines)
s = s.encode(encoding)
# s is your idf string

# **Or do stuff here**
enconded string ready to write

with open('myfile.idf', 'wb') as idf_out:
    idf_out.write(s)