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

Revision history [back]

click to hide/show revision 1
initial version

This code will do the trick

import eppy

# open some files form the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

This code will do the trick

import eppy

# open some files form from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

# if you have 5 or 6 idfs
# idfs = [idf1, idf2m idf3, idf4, idf5, idf6]
# untested code follows
version = idfs[0].idfobjects['version'][0]
version_number = version.Version_Identifier
idf_merged = eppy.newidf(version=version_number)

for idf in idfs:
    or key in idf.idfobjects:
        for idfobject in idf.idfobjects[key]:
            idf_merged.copyidfobject(idfobject)

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

# if you have 5 or 6 idfs
# idfs = [idf1, idf2m idf3, idf4, idf5, idf6]
# untested code follows
version = idfs[0].idfobjects['version'][0]
version_number = version.Version_Identifier
idf_merged = eppy.newidf(version=version_number)

for idf in idfs:
    or for key in idf.idfobjects:
        for idfobject in idf.idfobjects[key]:
            idf_merged.copyidfobject(idfobject)

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

# if you have 5 or 6 idfs
# idfs = [idf1, idf2m idf3, idf4, idf5, idf6]
# untested code follows
version = idfs[0].idfobjects['version'][0]
version_number = version.Version_Identifier
idftxt = "" # empty string
from io import StringIO
fhandle = StringIO(idftxt) # we can make a file handle of a string
idf_merged = eppy.newidf(version=version_number)
IDF(fhandle) # initialize the IDF object with the file handle

for idf in idfs:
    for or key in idf.idfobjects:
        for idfobject in idf.idfobjects[key]:
            idf_merged.copyidfobject(idfobject)

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

# if you have 5 or 6 idfs
# idfs = [idf1, idf2m idf3, idf4, idf5, idf6]
# untested code follows
idftxt = "" # empty string
from io import StringIO
fhandle = StringIO(idftxt) # we can make a file handle of a string
idf_merged = IDF(fhandle) # initialize the IDF object with the file handle

for idf in idfs:
    or for key in idf.idfobjects:
        for idfobject in idf.idfobjects[key]:
            idf_merged.copyidfobject(idfobject)

This code will do the trick

import eppy

# open some files from the example folder
fname1 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneEvapCooler.idf"
idf1 = eppy.openidf(fname1) # will search and find the IDD file if it can :-)
fname2 = "/Applications/EnergyPlus-9-3-0/ExampleFiles/1ZoneParameterAspect.idf"
idf2 = eppy.openidf(fname2)  # will search and find the IDD file if it can :-)

# code to merge the idf2 into idf1
for key in idf2.idfobjects:
    for idfobject in idf2.idfobjects[key]:
        idf1.copyidfobject(idfobject)

idf1.saveas('a.idf') # maybe ....

I just noticed that your question says that you do not want to loop thru using copyidfobject(). I can't think of any way of doing the merge without looping through. There is no merge function in eppy. That looping thru is your merge function. I guess eppy is not as eppy-sh as it should be.

# if you have 5 or 6 idfs
# idfs = [idf1, idf2m idf3, idf4, idf5, idf6]
# untested code follows

from eppy.modeleditor import IDF
idftxt = "" # empty string
from io import StringIO
fhandle = StringIO(idftxt) # we can make a file handle of a string
idf_merged = IDF(fhandle) # initialize the IDF object with the file handle

for idf in idfs:
    for key in idf.idfobjects:
        for idfobject in idf.idfobjects[key]:
            idf_merged.copyidfobject(idfobject)

idf_merged.saveas('merged.idf')   # save() won't work, since you don't have a file name