Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get idfobjects by regex #423

Open
crossingchen opened this issue Jul 19, 2023 · 5 comments
Open

Get idfobjects by regex #423

crossingchen opened this issue Jul 19, 2023 · 5 comments

Comments

@crossingchen
Copy link

I'm trying to get all the schedule objects in an idf by using idf1.idfobjects["SCHEDULE:COMPACT"] and idf1.idfobjects["SCHEDULE:CONSTANT"]. Is there a way to get all schedules using something like idf1.idfobjects["SCHEDULE:"] to match all object types start with "SCHEDULE:" instead of having the specify the full string of the object type?

@santoshphilip
Copy link
Owner

@crossingchen There is no builtin way to do this.
idf1.idfobjects is a dictionary SCHEDULE:COMPACT is a key in the dictionary. You need to use the full key.

I just played around with some code

import eppy
fname = "/Applications/EnergyPlus-23-1-0/ExampleFiles/5Zone_IdealLoadsAirSystems_ReturnPlenum.idf"
idf = eppy.openidf(fname)


# using standard loops
scheduleobjects = []
for key in idf.idfobjects.keys():
    if key.startswith('SCHEDULE'):
        for obj in idf.idfobjects[key]:
            scheduleobjects.append(obj)
        
# using list comprehension
scheduleobjects_again = [obj  for key in idf.idfobjects.keys() 
            if key.startswith('SCHEDULE') 
                for obj in idf.idfobjects[key]]

You can write a function to do this
Maybe the function can take a regex ?

@crossingchen
Copy link
Author

Sounds good. Let me try and create a PR.

@santoshphilip
Copy link
Owner

What do you think the function should be called ?

@crossingchen
Copy link
Author

Thanks. I looked into this a bit and it's probably best to use a function in my script as you suggested.

@santoshphilip
Copy link
Owner

I would say - Best to start with a function in your script.
The step back and take a look at it to see if it makes sense to make it a part of eppy.

If it does. make sense, we can look what to call it, how the code fits within eppy etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants