Load OSM file in measure scripting
How do I get a measure to load a specific OSM from a resources directory. I am using the following code and it finds the model but doesn't load it in to be run.
# assign the user inputs to variables
osm_file_name = runner.getStringArgumentValue("osm_file_name", user_arguments)
osm_directory = runner.getStringArgumentValue("osm_directory", user_arguments)
# get the path
osm_directory = File.expand_path(File.join(File.dirname(__FILE__), osm_directory))
#merge file name and path
osm_file = File.join(osm_directory, osm_file_name)
translator = OpenStudio::OSVersion::VersionTranslator.new
ospath = OpenStudio::Path.new(osm_directory)
model = translator.loadModel(ospath)
model = model.get
Thank you Eric and Matt. I am not having any luck yet. But I did start cross referencing this thread https://unmethours.com/question/19123... and seem to be going in the right direction. Can I use a relative path? Because I think my path definition is wrong.
I think it depends...is
osm_directory
located in the measure folder? Like, I have a measure where the folder contains a/resources
subfolder, and it lets me load"#{File.dirname(__FILE__)}/resources/#{file_name}"
. If you're trying to access a folder outside of the measure folder, I think a relative path will fail because the measure gets moved around when it's applied (also depending on how it's applied).I agree with Eric here - I think you'll need a hardcoded path unless you put a file in the resources folder of the measure.
Thank you for all of the feedback. I am going to start with hardcoding the path and then build out from there. Baby steps for me.
I will update and mark complete once I've tried.