How to find OSM file location from a measure?
I'm writing a measure to write CSV files to the OSM file folder and wondering if there's a way to find the location of the OSM file? Since OS uses the C:\Users\<UserName>\AppData\Local\Temp
folder during a sim, using the location of the measure.rb
file returns the Temp folder instead of the location of the actual OSM file. For example, a new reporting measure uses the code below to read/write to the measure folder.
html_in_path = "#{File.dirname(__FILE__)}/resources/report.html.in"
I'm using the following syntax to move up folders to write to a higher level of the directory. However, when the path is written out it shows the Temp folder path.
html_root_dir = "#{File.expand_path("../../../", __FILE__)}"
puts html_root_dir
HTML ROOT DIR = C:/USERS/MATT/APPDATA/LOCAL/TEMP/OPENSTUDIO.A17988/RESOURCES/RUN
The main block of Ruby code from the measure will function as intended if executed from a terminal outside of a simulation.
Are you writing a measure to run during the simulation workflow or using apply measures now? If you are writing a simulation workflow measure you should just write to the current directory that the measure is being run in. If you using apply measure now, you are right that the measure is run in a temporary location. There is not currently a way to find the OSM location from within a measure. Maybe you could just write to your home directory for now?
I'd like the measure to run during the simulation and I'm using the
.expand_path()
method to move up from the measure directory (see updated code above).That may work for now but just as a warning this will not likely work on the OpenStudio Server, this may also be disabled in the future as measures should not have access to write outside of their run directory. If you are using this in a simulation workflow I'd suggest just writing to the current directory, this will appear with all other measure output and results.