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

Is there a way to find all objects that use a particular schedule?

asked 2022-10-31 11:22:28 -0500

kgovie's avatar

updated 2023-01-18 16:21:44 -0500

I am creating an openstudio power outage measure using openstudio CLI (command line interface) that modifies all the schedules in the entire model.

First, I wrote a code to modify the schedule file. Then, I created a loop to identify each schedule and translate them to a ruleset with three parts: pre-outage, outage, post-outage.

I am stuck on the step where I need to pull out all the model objects that use the original schedule, so I can change schedule from the original one to the new outage ruleset.

in Ruby:

model.getSchedules.each do |sch|
 < a lot of code here >
 model.getModelObjects.each do |obj|
       # Find obj whose schedule == sch (STUCK HERE)
  end 
end

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-11-01 11:44:25 -0500

ScheduleBase is a child class of ResourceObject. The ModelObject class has a resources method that returns a list of ResourceObjects directly used by instances of that class. So one way to get all model objects that use a particular schedule would be:

objects = []
model.getModelObjects.each do |obj|
  if obj.resources.include?(schedule)
    objects << obj
  end
end

That won't tell you _how_ the object uses the schedule - i.e. as an availabilitySchedule or something else, just that the object references the schedule somewhere.

edit flag offensive delete link more

Comments

Clever approach. Unfortunately it only gets @catknitski halfway there; they will still have to write object-specific code/logic in order to swap out the appropriate schedule.

shorowit's avatar shorowit  ( 2022-11-01 19:30:01 -0500 )edit

Here is the code I have so far. I know how to get to the specific objects semi-maually in the code. https://github.com/NEU-ABLE-LAB/commu...

Its just that if there are model objects not included in lines 218-237 the schedule will not get updated.

kgovie's avatar kgovie  ( 2022-11-02 13:39:07 -0500 )edit

@catknitski looks like your link is to a private repo, or is otherwise missing - I get a 404 error.

ericringold's avatar ericringold  ( 2022-11-02 14:10:44 -0500 )edit

Good catch. I made a public repo. https://github.com/govertsenk/myphddi...

kgovie's avatar kgovie  ( 2022-11-02 15:48:07 -0500 )edit

Your Answer

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

Add Answer

Careers

Question Tools

1 follower

Stats

Asked: 2022-10-31 11:22:28 -0500

Seen: 8,177 times

Last updated: Nov 01 '22