lib/openstudio-standards/btap/fileio.rb in openstudio-standards-0.1.4 vs lib/openstudio-standards/btap/fileio.rb in openstudio-standards-0.1.5
- old
+ new
@@ -19,11 +19,11 @@
require "#{File.dirname(__FILE__)}/btap"
require 'fileutils'
require 'csv'
-require 'rubygems'
+#require 'rubygems'
module BTAP
module FileIO
@@ -158,10 +158,12 @@
model.addObjects( new_model.toIdfFile.objects )
BTAP::runner_register("Info", "Model name is now #{model.building.get.name}.", runner)
end
+
+
# This method loads an Openstudio file into the model.
# @author Phylroy A. Lopez
# @param filepath [String] path to the OSM file.
# @param name [String] optional model name to be set to model.
@@ -227,13 +229,43 @@
# Simply because I don't trust the clone method yet.
# @author Phylroy A. Lopez
# @return [OpenStudio::Model::Model] a copy of the OpenStudio model object.
def self.deep_copy(model,bool = true)
return model.clone(bool).to_Model
- # model.save(OpenStudio::Path.new("deep_copy.osm"))
- # model_copy = self.load_osm("deep_copy.osm")
- # File.delete("deep_copy.osm")
- # return model_copy
+
+ # pull original weather file object over
+ weather_file = new_model.getOptionalWeatherFile
+ if not weather_file.empty?
+ weather_file.get.remove
+ BTAP::runner_register("Info", "Removed alternate model's weather file object.",runner)
+ 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 new_model
+ # remove existing objects from model
+ handles = OpenStudio::UUIDVector.new
+ model.objects.each do |obj|
+ handles << obj.handle
+ end
+ model.removeObjects(handles)
+ # add new file to empty model
+ model.addObjects( new_model.toIdfFile.objects )
+ BTAP::runner_register("Info", "Model name is now #{model.building.get.name}.", runner)
+
+
+
+
end
# This method will save the model to an osm file.
# @author Phylroy A. Lopez
# @param model
\ No newline at end of file