Class: BTAP::Measures::OSMeasures::ArchetypeScan

Inherits:
BTAPModelUserScript
  • Object
show all
Defined in:
lib/openstudio-standards/btap/measures.rb

Instance Attribute Summary

Attributes inherited from BTAPModelUserScript

#argument_array_of_arrays, #file

Instance Method Summary collapse

Methods inherited from BTAPModelUserScript

#argument_getter, #argument_setter, #generate_ruby_macro

Instance Method Details

#arguments(model) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/openstudio-standards/btap/measures.rb', line 339

def arguments(model)
  #get all osm files in resource folder.

  osmfiles = OpenStudio::StringVector.new
  BTAP::FileIO::get_find_files_from_folder_by_extension(File.dirname(__FILE__), ".osm").each {|filename| osmfiles << File.basename(file_name, ",osm")}


  #list of arguments as they will appear in the interface. They are available in the run command as @variable_name.

  @argument_array_of_arrays = [
    [    "variable_name",          "type",          "required",  "model_dependant", "display_name",         "default_value",  "min_value",  "max_value",  "string_choice_array",    "os_object_type" ],
    [    "archetype_name",         "STRINGCHOICE",  true,         false,            "archetype_name",       osmfiles[0].to_s ,        nil,          nil,          osmfiles,   nil         ],
  ]
  args = super(model,@argument_array_of_arrays)
  return args
end

#nameObject



335
336
337
# File 'lib/openstudio-standards/btap/measures.rb', line 335

def name
  "BTAPTempModelMeasure"
end

#run(model, runner, user_arguments) ⇒ Object



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/openstudio-standards/btap/measures.rb', line 354

def run(model, runner, user_arguments)
  #run the super

  parent_method_is_true = super(model, runner, user_arguments)
  
  
  ###############

  
  #Set Archetype name in runner. 

  runner.registerValue('archetype_name',@archetype_name)
  
  #Set path to OSM files. 

  alternative_model_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/#{@archetype_name}.osm")
  #load model and test.

  translator = OpenStudio::OSVersion::VersionTranslator.new
  oModel = translator.loadModel(alternative_model_path)
  if oModel.empty?
    runner.registerError("Could not load alternative model from '" + alternative_model_path.to_s + "'.")
    return false
  end
  new_model = oModel.get

  # pull original weather file object over

  weather_file = new_model.getOptionalWeatherFile
  if not weather_file.empty?
    weather_file.get.remove
    runner.registerInfo("Removed alternate model's weather file object.")
  end
  original_weather_file = model.getOptionalWeatherFile
  if not original_weather_file.empty?
    original_weather_file.get.clone(new_model)
  end

  # pull original design days over

  new_model.getDesignDays.each { |designDay| designDay.remove }
  model.getDesignDays.each { |designDay| designDay.clone(new_model) }

  #swap underlying data in model with underlying data in newModel

  model.swap(new_model)
  runner.registerFinalCondition("Model replaced with alternative #{alternative_model_path}.")
  return  true ? parent_method_is_true  : false
end

#set_user_arguments_and_apply(model, argument_values, runner) ⇒ Object

For manually running script via an IDE or a command line script. Using the template above as an example.….

argument_values = [
     ["archetype_name",     "FullServiceRestaurant" ]
  ]


402
403
404
# File 'lib/openstudio-standards/btap/measures.rb', line 402

def set_user_arguments_and_apply(model,argument_values,runner)
  self.run(model, runner, super(model,argument_values,runner) )
end