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

Revision history [back]

If you're certain the osm version is the same as the API you are using, the following should work:

model = OpenStudio::Model::Model.load(osm_file).get

If you're certain the osm version is the same as the API you are using, the following should work:

model = OpenStudio::Model::Model.load(osm_file).get

The 'safer' way, as @mdahlhausen suggested, is to load thru the version translator, like:

model_path = OpenStudio::Path.new(osm_path)
version_translator = OpenStudio::OSVersion::VersionTranslator.new

if OpenStudio::exists(model_path)
  model = version_translator.loadModel(model_path)
  if model.empty?
    puts "Version translation failed for #{model_path}"
  else
    model = model.get
  end
else
  puts "The model couldn't be found at #{model_path}"
end

If you're certain the osm version is the same as the API you are using, the following should work:

model = OpenStudio::Model::Model.load(osm_file).get

The 'safer' way, as @mdahlhausen suggested, is to load thru the version translator, as well as checking that everything exists ('is_initialized', or not 'empty') like:

model_path = OpenStudio::Path.new(osm_path)
version_translator = OpenStudio::OSVersion::VersionTranslator.new

if OpenStudio::exists(model_path)
  model = version_translator.loadModel(model_path)
  if model.empty?
    puts "Version translation failed for #{model_path}"
  else
    model = model.get
  end
else
  puts "The model couldn't be found at #{model_path}"
end

If you're certain the osm version is the same as the API you are using, the following should work:

model = OpenStudio::Model::Model.load(osm_file).get

The 'safer' way, as @mdahlhausen suggested, is to load thru the version translator, as well as checking that everything exists ('is_initialized', or not 'empty') 'empty'). As a handy function, it would look like:

def load_model(osm_path)
  model_path = OpenStudio::Path.new(osm_path)
 version_translator = OpenStudio::OSVersion::VersionTranslator.new

 if OpenStudio::exists(model_path)
   model = version_translator.loadModel(model_path)
   if model.empty?
     puts "Version translation failed for #{model_path}"
   else
     model = model.get
      return model
    end
 else
   puts "The model couldn't be found at #{model_path}"
  end
end