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

Revision history [back]

You hit one of the rare model objects that changed from 1.x to 2.x. The 'Meter' object was changed to 'OutputMeter. I have updated the measure and will try to push i to BCL this afternoon, but it is pretty short, so if you want to you can replace the run method of your measure.rb with this.

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

#assign the user inputs to variables
meter_name = runner.getStringArgumentValue("meter_name",user_arguments)
reporting_frequency = runner.getStringArgumentValue("reporting_frequency",user_arguments)

#check the user_name for reasonableness
if meter_name == ""
  runner.registerError("No meter name was entered.")
  return false
end

meters = model.getOutputMeters
#reporting initial condition of model
runner.registerInitialCondition("The model started with #{meters.size} meter objects.")

#flag to add meter
add_flag = true

# OpenStudio doesn't like two meters of the same name, even if they have different reporting frequencies.
meters.each do |meter|
  if meter.name == meter_name
  runner.registerWarning("A meter named #{meter_name} already exists. One will not be added to the model.")
    if not meter.reportingFrequency == reporting_frequency
      meter.setReportingFrequency(reporting_frequency)
      runner.registerInfo("Changing reporting frequency of existing meter to #{reporting_frequency}.")
    end
  add_flag = false
  end
end

if add_flag
  meter = OpenStudio::Model::OutputMeter.new(model)
  meter.setName(meter_name)
  meter.setReportingFrequency(reporting_frequency)
  runner.registerInfo("Adding meter for #{meter.name} reporting #{reporting_frequency}")
end

meters = model.getOutputMeters
#reporting final condition of model
runner.registerFinalCondition("The model finished with #{meters.size} meter objects.")

return true

You hit one of the rare model objects that changed from 1.x to 2.x. The 'Meter' object was changed to 'OutputMeter. '. I have updated the measure and will try to push i to BCL this afternoon, but it is pretty short, so if you want to you can replace the run method of your measure.rb with this.

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

#assign the user inputs to variables
meter_name = runner.getStringArgumentValue("meter_name",user_arguments)
reporting_frequency = runner.getStringArgumentValue("reporting_frequency",user_arguments)

#check the user_name for reasonableness
if meter_name == ""
  runner.registerError("No meter name was entered.")
  return false
end

meters = model.getOutputMeters
#reporting initial condition of model
runner.registerInitialCondition("The model started with #{meters.size} meter objects.")

#flag to add meter
add_flag = true

# OpenStudio doesn't like two meters of the same name, even if they have different reporting frequencies.
meters.each do |meter|
  if meter.name == meter_name
  runner.registerWarning("A meter named #{meter_name} already exists. One will not be added to the model.")
    if not meter.reportingFrequency == reporting_frequency
      meter.setReportingFrequency(reporting_frequency)
      runner.registerInfo("Changing reporting frequency of existing meter to #{reporting_frequency}.")
    end
  add_flag = false
  end
end

if add_flag
  meter = OpenStudio::Model::OutputMeter.new(model)
  meter.setName(meter_name)
  meter.setReportingFrequency(reporting_frequency)
  runner.registerInfo("Adding meter for #{meter.name} reporting #{reporting_frequency}")
end

meters = model.getOutputMeters
#reporting final condition of model
runner.registerFinalCondition("The model finished with #{meters.size} meter objects.")

return true