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

Revision history [back]

@pajordan that is a good question. For many users, if your files are named "report.html" you can just access the files from the PAT GUI and avoid manually going through the "localResutls" folder, but there are certainly use cases for needing to directly access those files. For now I just use a stand alone ruby script that I run after the analysis has finished, that copes a specific file I need to a common location. It copies a renamed copy of file using argument or output value or values. In this case I had a single runner.registerValue I know as unique, but you could concatenate a combination of arguments and outputs. This can be used for manual or algorithmic workflow.

# require fileutils and openstudio
require 'fileutils'
require 'openstudio'

# source and target directories
project_directory = "0525_Reopt_test"
target_directory = "reopt_csv_files"

# loop through resoruce files
results_directories = Dir.glob("#{project_directory}/LocalResults/*")
results_directories.each do |results_directory|

    idf_building_name = nil

    # create an instance of a runner with OSW
    osw_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/#{results_directory}/out.osw")
    osw = OpenStudio::WorkflowJSON.load(osw_path).get
    runner = OpenStudio::Ruleset::OSRunner.new(osw)

    # 2.x methods (currently setup for measure display name but snake_case arg names)
    runner.workflow.workflowSteps.each do |step|
      if step.to_MeasureStep.is_initialized
        measure_step = step.to_MeasureStep.get

        measure_name = measure_step.measureDirName
        if measure_step.name.is_initialized
          measure_name = measure_step.name.get # this is instance name in PAT
        end
        if measure_step.result.is_initialized
          result = measure_step.result.get
          result.stepValues.each do |arg|
            next if not arg.name == "some_argument_or_register_value_from_osw"
            value = arg.valueAsVariant.to_s
            new_name = value
            puts "#{measure_name}: #{arg.name} = #{value}"
          end
        else
          #puts "No result for #{measure_name}"
        end
      else
        #puts "This step is not a measure"
      end
    end

    # copy and rename file
    orig_file = "#{File.dirname(__FILE__)}/#{results_directory}/hourly_consumption_by_fuel_to_csv_report.csv"
    copy_file = "#{target_directory}/#{new_name}.csv"
    if File.file?(orig_file)
        puts "Creating #{copy_file}"
        FileUtils.cp(orig_file, copy_file)
    end

end

The code above uses the OSW to get information used to rename the file. You could also open up the OSM file and rename based on characteristics of the model that you know are unique. I'm not sure if the OSW has access to the design alternative name, but I can look into that.

@pajordan that is a good question. For many users, if your files are named "report.html" you can just access the files from the PAT GUI and avoid manually going through the "localResutls" folder, but there are certainly use cases for needing to directly access those files. For now I just use a stand alone ruby script that I run after the analysis has finished, that copes a specific file I need to a common location. It copies a renamed copy of file using argument or output value or values. In this case I had a single runner.registerValue I know as unique, but you could concatenate a combination of arguments and outputs. This can be used for manual or algorithmic workflow.

# require fileutils and openstudio
require 'fileutils'
require 'openstudio'

# source and target directories
project_directory = "0525_Reopt_test"
target_directory = "reopt_csv_files"

# loop through resoruce files
results_directories = Dir.glob("#{project_directory}/LocalResults/*")
results_directories.each do |results_directory|

    idf_building_name = nil

    # create an instance of a runner with OSW
    osw_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/#{results_directory}/out.osw")
    osw = OpenStudio::WorkflowJSON.load(osw_path).get
    runner = OpenStudio::Ruleset::OSRunner.new(osw)

    # 2.x methods (currently not setup for measure display name but snake_case arg names)
    runner.workflow.workflowSteps.each do |step|
      if step.to_MeasureStep.is_initialized
        measure_step = step.to_MeasureStep.get

        measure_name = measure_step.measureDirName
        if measure_step.name.is_initialized
          measure_name = measure_step.name.get # this is instance name in PAT
        end
        if measure_step.result.is_initialized
          result = measure_step.result.get
          result.stepValues.each do |arg|
            next if not arg.name == "some_argument_or_register_value_from_osw"
            value = arg.valueAsVariant.to_s
            new_name = value
            puts "#{measure_name}: #{arg.name} = #{value}"
          end
        else
          #puts "No result for #{measure_name}"
        end
      else
        #puts "This step is not a measure"
      end
    end

    # copy and rename file
    orig_file = "#{File.dirname(__FILE__)}/#{results_directory}/hourly_consumption_by_fuel_to_csv_report.csv"
    copy_file = "#{target_directory}/#{new_name}.csv"
    if File.file?(orig_file)
        puts "Creating #{copy_file}"
        FileUtils.cp(orig_file, copy_file)
    end

end

The code above uses the OSW to get information used to rename the file. You could also open up the OSM file and rename based on characteristics of the model that you know are unique. I'm not sure if the OSW has access to the design alternative name, but I can look into that. that.