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

Revision history [back]

Openstudio measure: deal with blank argument

I want to include an optional argument for a measure, that the user would leave blank if not needed. The problem is that when I'm trying to retrieve the value, if left blank it crashes.

Here's an example of what I want to do:

def arguments(model)
  args = OpenStudio::Ruleset::OSArgumentVector.new

  #Optional argument
  fan_pressure_rise = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('fan_pressure_rise', false)
  fan_pressure_rise.setDisplayName('Fan Pressure Rise (Pa)')
  fan_pressure_rise.setDescription('Leave blank for default value')
  args << fan_pressure_rise

  return args
end # end the arguments method

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

  fan_pressure_rise = runner.getDoubleArgumentValue('fan_pressure_rise', user_arguments)

  return true

end # end the run method

I get the following error:

'getDoubleArgumentValue': No value found for argument 'fan_pressure_rise' (RuntimeError)

How can I deal with optional, potentially blank arguments in OpenStudio measures?

Openstudio measure: deal with blank argument

I want to include an optional argument for a measure, that the user would leave blank if not needed. The problem is that when I'm trying to retrieve the value, if left blank it crashes.

Here's an example of what I want to do:

def arguments(model)
  args = OpenStudio::Ruleset::OSArgumentVector.new

  #Optional argument
  fan_pressure_rise = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('fan_pressure_rise', false)
  fan_pressure_rise.setDisplayName('Fan Pressure Rise (Pa)')
  fan_pressure_rise.setDescription('Leave blank for default value')
  args << fan_pressure_rise

  return args
end # end the arguments method

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

  fan_pressure_rise = runner.getDoubleArgumentValue('fan_pressure_rise', user_arguments)

  [...truncated...]

  if !fan_pressure_rise.empty?
    selected_fan.setPressureRise(fan_pressure_rise)
  end


  return true

end # end the run method

I get the following error:

'getDoubleArgumentValue': No value found for argument 'fan_pressure_rise' (RuntimeError)

How can I deal with optional, potentially blank arguments in OpenStudio measures?

Update

I figured I should use

fan_pressure_rise = runner.getOptionalDoubleArgumentValue('fan_pressure_rise', user_arguments)

For reference, the list of get...ArgumentValue available is in the OSRunner Class Reference.

Problem is, selected_fan.setPressureRise(fan_pressure_rise) crashes because it expects a Double, not an OptionalDouble.

I can't find how to convert an OptionalDouble to a Double. I tried fan_pressure_rise_double = OpenStudio::Double.new(fan_pressure_rise) but that doesn't work.

Openstudio measure: deal with blank argument

I want to include an optional argument for a measure, that the user would leave blank if not needed. The problem is that when I'm trying to retrieve the value, if left blank it crashes.

Here's an example of what I want to do:

def arguments(model)
  args = OpenStudio::Ruleset::OSArgumentVector.new

  #Optional argument
  fan_pressure_rise = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('fan_pressure_rise', false)
  fan_pressure_rise.setDisplayName('Fan Pressure Rise (Pa)')
  fan_pressure_rise.setDescription('Leave blank for default value')
  args << fan_pressure_rise

  return args
end # end the arguments method

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

  fan_pressure_rise = runner.getDoubleArgumentValue('fan_pressure_rise', user_arguments)

  [...truncated...]

  if !fan_pressure_rise.empty?
    selected_fan.setPressureRise(fan_pressure_rise)
  end


  return true

end # end the run method

I get the following error:

'getDoubleArgumentValue': No value found for argument 'fan_pressure_rise' (RuntimeError)

How can I deal with optional, potentially blank arguments in OpenStudio measures?

Update

I figured I should use

fan_pressure_rise = runner.getOptionalDoubleArgumentValue('fan_pressure_rise', user_arguments)

For reference, the list of get...ArgumentValue available is in the OSRunner Class Reference.

Problem is, selected_fan.setPressureRise(fan_pressure_rise) crashes because it expects a Double, not an OptionalDouble.

I can't find how to convert an OptionalDouble to a Double. I tried fan_pressure_rise_double = OpenStudio::Double.new(fan_pressure_rise) but that doesn't work.