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

OS argument option

asked 2016-01-24 08:23:47 -0500

ngkhanh's avatar

updated 2016-01-24 16:54:58 -0500

Hi I made a few code for measure input :

    def arguments(model)
      args = OpenStudio::Ruleset::OSArgumentVector.new
      args = OpenStudio::Ruleset::OSArgumentVector.new
      d_auto_fan_sch = model.alwaysOffDiscreteSchedule
      d_auto_fan_sch.setName("VRF TU auto fan schedule")
      always_on = model.alwaysOnDiscreteSchedule
      # HVAC schedule choice
      chs = OpenStudio::StringVector.new
      chs << "Yes"
      chs << "No"
      sch_chs = OpenStudio::Ruleset::OSArgument::makeChoiceArgument('Optional_sch', chs, true)
      sch_chs.setDisplayName("Does HVAC work all day ?")
      sch_chs.setDefaultValue("Yes")
      args << sch_chs
      #pick a schedule
      #sched_names = OpenStudio::Ruleset::makeChoiceArgumentOfWorkspaceObjects("HVAC Schedule Name","OS_Schedule_Ruleset".to_IddObjectType,model,true)
      all_scheds = model.getSchedules
      sched_name_vec = OpenStudio::StringVector.new
      all_scheds.each do |sched|
        sched_name_vec << sched.name.get
      end
      sched_names = OpenStudio::Ruleset::OSArgument::makeChoiceArgument('HVAC Schedule name', sched_name_vec, true)
      sched_names.setDisplayName("Choose a HVAC schedule")
      sched_names.setDefaultValue("#{always_on.name}")
      args << sched_names
      sched_names1 = OpenStudio::Ruleset::OSArgument::makeChoiceArgument('Supply fan Schedule name', sched_name_vec, true)
      sched_names1.setDisplayName("Choose supply fan schedule")
      sched_names1.setDefaultValue("#{d_auto_fan_sch.name}")
      args << sched_names1
      return args 
  end #end the arguments method

  #define what happens when the measure is run
  def run(model, runner, user_arguments)
    super(model, runner, user_arguments)

    #use the built-in error checking 
    if not runner.validateUserArguments(arguments(model), user_arguments)
      return false
    end
    # setup schedule 

    s_sup_fan_option = runner.getStringArgumentValue('Supply fan Schedule name',user_arguments)
    s_scheds = model.getSchedules
    s_scheds.each do |sched|
      if sched.name.get == s_sup_fan_option
      @@schd1 = sched
      end
    end  
    runner.registerInfo(" Set all VRF Terminal unit supply fan schedule as #{@@schd1.name} ")

I created temporary schedule as default schedule for supply fan schedule but they got this warning :

The default value of script argument Supply fan Schedule name (Choose supply fan schedule) Choice, Required Value: (VRF TU auto fan schedule 1) does not match that of the corresponding user argument Supply fan Schedule name (Choose supply fan schedule) Choice, Required Value: VRF TU auto fan schedule (VRF TU auto fan schedule)

each time i try to repeat this measure, they add a new schedule (VRF TU auto fan schedule 1)

How to avoid warning and unnecessary schedule ?

Note : Have any pathway for show the code as cool as in Unmethours in Notepad++ ???

edit retag flag offensive close merge delete

Comments

Note: switch to emacs :)

__AmirRoth__'s avatar __AmirRoth__  ( 2016-01-24 10:24:02 -0500 )edit

Thanks but emacs is much less productive than notepad++ in search and hotkey. Maybe im not familiar with emacs. I would like to know the pathway to change notepad++ color index so its GUI as cool as emacs. How to get emacs color index for ruby so that i can change notepad++ ??

ngkhanh's avatar ngkhanh  ( 2016-01-24 11:37:37 -0500 )edit

can't help you with notepad++ unfortunately. good luck.

__AmirRoth__'s avatar __AmirRoth__  ( 2016-01-24 13:02:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-01-24 16:53:29 -0500

The issue here is that changes made to the model in the arguments section are not persisted (a clone of the model is passed into the arguments method rather than the actual model). So when you set the name of that schedule in the arguments section, the schedule name changes in the cloned model but not in the model you are working with. When the model is passed into the run method the schedule has the original name.

The other note is that you should not change the name of the alwaysOffDiscreteSchedule, the model finds that schedule by name so if you change the name the model will not find it and will create a new one. I would suggest making the default be either the d_auto_fan_sch.name (without your changes) or make it be some key like "New Schedule". If "New Schedule" is passed in, you can clone the alwaysOffDiscreteSchedule, change it's name, and use that for your needs.

edit flag offensive delete link more

Comments

Here is the code where the clone happens.

macumber's avatar macumber  ( 2016-01-24 16:58:32 -0500 )edit

i tried a variety of options and none of them succeed to make a default schedule shown in argument section without warning. May i make run1 section for create schedule in advance and use it in argument section then run2 for model modifying? Other pathway is welcome.

ngkhanh's avatar ngkhanh  ( 2016-01-26 15:25:47 -0500 )edit

Any objects you make in the arguments section are not going to be available in the run section.

macumber's avatar macumber  ( 2016-01-26 16:54:07 -0500 )edit

Near to finish line!! the additonal schedule doesn't get more but I till have minor error with this code

schedule_add = OpenStudio::Ruleset::OSArgument::makeBoolArgument('@add_sched',false)
    schedule_add.setValue(false)
    args << schedule_add

I dont want to show check box '@add_sched' while still need set "false" value for @add_sched as argument.

ngkhanh's avatar ngkhanh  ( 2016-01-27 09:50:35 -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

2 followers

Stats

Asked: 2016-01-24 08:23:47 -0500

Seen: 224 times

Last updated: Jan 24 '16