Class: FromIDFModel

Inherits:
OpenStudio::Measure::ModelMeasure
  • Object
show all
Defined in:
lib/measures/from_idf_model/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/measures/from_idf_model/measure.rb', line 55

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

  # Make an argument for the OpenStudio model
  idf_model = OpenStudio::Measure::OSArgument.makeStringArgument('idf_model', true)
  idf_model.setDisplayName('Path to the IDF Model')
  args << idf_model

  # Make an argument for the output file path
  output_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('output_file_path', true)
  output_file_path.setDisplayName('Output file path')
  output_file_path.setDescription('If set, the output Honeybee JSON file will be exported to this path. Othervise The file will be exported to the same path as the IDF model.')
  output_file_path.setDefaultValue('')
  args << output_file_path

  return args
end

#descriptionObject

human readable description



45
46
47
# File 'lib/measures/from_idf_model/measure.rb', line 45

def description
  return "Translate an IDF into a JSON file of a Honeybee Model."
end

#modeler_descriptionObject

human readable description of modeling approach



50
51
52
# File 'lib/measures/from_idf_model/measure.rb', line 50

def modeler_description
  return "Translate an IDF into a JSON file of a Honeybee Model."
end

#nameObject

human readable name



40
41
42
# File 'lib/measures/from_idf_model/measure.rb', line 40

def name
  return "From IDF Model"
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/measures/from_idf_model/measure.rb', line 74

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)
  STDOUT.flush
  if !runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end

  idf_model = runner.getStringArgumentValue('idf_model', user_arguments)

  idf_model_path, idf_model_name = File.split(idf_model)
  honeybee_model_name = idf_model_name.split('.')[0] + '.hbjson'

  if !File.exist?(idf_model)
    runner.registerError("Cannot find file '#{idf_model}'")
    return false
  end

  honeybee_model = Honeybee::Model.translate_from_idf_file(idf_model)
  honeybee_hash = honeybee_model.hash

  output_file_path = runner.getStringArgumentValue('output_file_path', user_arguments)

  if output_file_path && !output_file_path.empty?
      unless File.exist?(output_file_path)
        output_folder = File.split(output_file_path)[0]
        FileUtils.mkdir_p(output_folder)
      end
  else
    output_file_path = File.join(idf_model_path, honeybee_model_name)
  end

  File.open(output_file_path, 'w') do |f|
    f.puts JSON::pretty_generate(honeybee_hash)
  end

  return true
end