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

How to find OSM file location from a measure?

asked 2015-06-26 11:41:20 -0600

updated 2017-08-05 13:32:18 -0600

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.

edit retag flag offensive close merge delete

Comments

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?

macumber's avatar macumber  ( 2015-06-26 14:38:49 -0600 )edit

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).

MatthewSteen's avatar MatthewSteen  ( 2015-06-27 16:45:47 -0600 )edit

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.

macumber's avatar macumber  ( 2015-06-27 18:42:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-07-01 10:30:56 -0600

updated 2015-07-01 10:50:16 -0600

During a simulation OS uses the Temp directory to read and write files. The contents of <OsmFolder>/run/ is copied to the Temp directory and then deleted after the new files are written and the simulation is completed. On Windows machines OS uses the path:

C:\Users\<UserName>\AppData\Local\Temp\OpenStudio.xxxxxx\resources\run\

The issue I had was in referencing the OSM directory structure rather than the Temp directory. So to have a measure write files during a simulation and have them appear in the OSM folder I had to make sure any paths used in the measure were relative to the measure file. The File.expand_path("../../../", __FILE__) worked well for moving around the Temp OSM directory.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2015-06-26 11:41:20 -0600

Seen: 340 times

Last updated: Jul 01 '15