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

How to export OSM to IDF with the command line?

asked 2021-01-14 05:54:22 -0600

Adrien's avatar

updated 2021-01-14 10:06:19 -0600

I can export my OpenStudio model with the OpenStudioApplication: File / Export / IDF. But I would like to do this from the command line (without running the simulation), is it possible? I can't find it on https://nrel.github.io/OpenStudio-use... or when typing openstudio.exe --help or openstudio list_commands.

Oh, I could edit the OSM file to introduce something that would make the simulation instantly fail and then retrieve the IDF from the run directory, but this is a bit cumbersome, I guess there's a better way :)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2021-01-14 14:40:29 -0600

If you need a one-liner without intermediate files, just call the CLI in a terminal like this:

openstudio -e "vt = OpenStudio::OSVersion::VersionTranslator.new; m = vt.loadModel('test.osm').get; ft = OpenStudio::EnergyPlus::ForwardTranslator.new; w = ft.translateModel(m); w.save('test.idf', true);"
edit flag offensive delete link more

Comments

Thank you! Since I prefer python, I installed your bindings and can also do it with:

python3 -c 'import openstudio;openstudio.energyplus.ForwardTranslator().translateModel(openstudio.osversion.VersionTranslator().loadModel(openstudio.path("test.osm")).get()).save(openstudio.path("test.idf"), True)'
Adrien's avatar Adrien  ( 2021-01-15 03:40:10 -0600 )edit

Yeah that works too, glad you're testing the python bindings too! I suppose we could also provide a CLI option directly... something like openstudio toidf <file> (or openstudio convert --idf <file>). Feel free to open an enhancement request on https://github.com/NREL/OpenStudio/is... if you think that'd be helpful.

Julien Marrec's avatar Julien Marrec  ( 2021-01-15 06:04:16 -0600 )edit

I don't need the extra CLI option, thanks :-)

Adrien's avatar Adrien  ( 2021-01-22 05:50:02 -0600 )edit
4

answered 2021-01-14 08:30:13 -0600

updated 2021-01-14 08:31:49 -0600

Here are two ways to generate the IDF using the OpenStudio CLI without running a simulation:

1. Use an OpenStudio Workflow (OSW)

Create a file called test.osw with the following contents:

{
  "seed_file": "test.osm"
}

Then run openstudio run -m -w test.osw, where the -m flag prevents the simulation from running. You will find the IDF at run/in.idf.

2. Use the OpenStudio SDK

Create a simple ruby script called generate_idf.rb with the following contents:

vt = OpenStudio::OSVersion::VersionTranslator.new
model = vt.loadModel(OpenStudio::Path.new("test.osm")).get
ft = OpenStudio::EnergyPlus::ForwardTranslator.new
model_idf = ft.translateModel(model)
File.open("test.idf", "w") { |f| f << model_idf.to_s }

Then run openstudio generate_idf.rb. It will create a test.idf file next to your test.osm file.

edit flag offensive delete link more

Comments

Awesome, thanks!

Adrien's avatar Adrien  ( 2021-01-14 08:34:52 -0600 )edit

Prefer using model_idf.save('path.idf', true) rather than File.open. The second argument (boolean) is whether you allow overwrite of an existing file or not.

Julien Marrec's avatar Julien Marrec  ( 2021-01-14 14:39:01 -0600 )edit
1

A long time ago, I was told that .to_s was much faster than .save. But I forget the exact reason (sorting objects?) and don't know whether it still applies.

shorowit's avatar shorowit  ( 2021-01-14 14:49:52 -0600 )edit

It seems to be faster, yet I wouldn't recommend the File.open to newcomers :)

require 'openstudio'
require 'benchmark'

m = OpenStudio::Model::exampleModel()
ft = OpenStudio::EnergyPlus::ForwardTranslator.new
w = ft.translateModel(m)
w.save('test_save.idf', true)
w.save('test_open.idf', true)

n = 100
Benchmark.bm(7) do |x|
  x.report("save:")   { n.times do   ; w.save('test_save.idf', true); end }
  x.report("File.open:") { n.times do   ; File.open("test_open.idf", "w") { |f| f << w.to_s }; end }
end
Julien Marrec's avatar Julien Marrec  ( 2021-01-14 14:58:19 -0600 )edit

Results

                 user     system      total        real
    save:     1.024476   0.268156   1.292632 (  1.292821)
    File.open:  0.892978   0.015530   0.908508 (  0.917008)
Julien Marrec's avatar Julien Marrec  ( 2021-01-14 14:58:28 -0600 )edit

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: 2021-01-14 05:54:22 -0600

Seen: 727 times

Last updated: Jan 15 '21