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.
@Julien Marrec, you are a beast!
What makes me a beast? More importantly, is that a good thing or a bad thing :) ?
I'm referring to your productivity on this site. And presumably off of it. I wish there were a 'beast' tag. :)
It's a good thing, definition: beast UK Slang- a person who is very good at something. Example: He's an absolute beast when it comes to football.
And @Amir Roth is right, you are a beast!