4

Best method for creating a ScheduleRule

When creating a schedule via ruby scripts, I create a new ScheduleRuleset object ruleset , then create a ScheduleDay object scheduleDay and finally create the associated ScheduleRule as:

rule = OpenStudio::Model::ScheduleRule.new(ruleset, scheduleDay)

This works just fine but (as indicated in the documentation) the ScheduleDay object is cloned and the new object is associated with the rule. Practically this is fine and the ruleset is created as expected but it leaves these orphaned ScheduleDay objects in the OSM.

My question is, is there a (non-hacky) way to create the ScheduleRules without polluting the OSM with a bunch of unused ScheduleDay objects? Or alternatively, if I create the rule without the ScheduleDay and a new ScheduleDay object is created, how do I access it?

Sam Currie's avatar
157
Sam Currie
asked 2016-05-31 16:30:29 -0500
ericringold's avatar
10.6k
ericringold
updated 2016-05-31 19:00:43 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

3

The ScheduleRule API was designed to disallow sharing of DaySchedules. So if you create the DaySchedule first and pass it in, you will have to delete the original yourself. If you use the other constructor (with a ScheduleRuleset but not ScheduleDay) the ScheduleRule will construct its own ScheduleDay. You can get that from the ScheduleRule later and modify it.

macumber's avatar
12k
macumber
answered 2016-05-31 21:30:44 -0500, updated 2016-05-31 21:45:35 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks @macumber. How does one access the ScheduleDay that the rule constructs? In the method list for ScheduleRule I'm not seeing a straight forward way to do so; is it necessary to call children() and search for the ScheduleDay?

Sam Currie's avatar Sam Currie (2016-06-01 16:26:03 -0500) edit
macumber's avatar macumber (2016-06-01 16:50:44 -0500) edit
add a comment see more comments